File: test-cos_sim_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 (36 lines) | stat: -rw-r--r-- 990 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
context("test-cos_sim_matrix")

# Read signatures
signatures <- get_known_signatures()


# Read mut_matrix
mut_mat <- readRDS(system.file("states/mut_mat_data.rds",
  package = "MutationalPatterns"
))


# Calculate the cosine similarity between each COSMIC signature and each 96 mutational profile
output <- cos_sim_matrix(mut_mat, signatures)

# Perform tests.
test_that("Output has correct class and data type", {
  expect_true(inherits(output, c("matrix")))
  expect_equal(typeof(output), "double")
})

test_that("Output has expected size", {
  expect_equal(dim(output), c(9, 60))
})

mut_mat_df = as.data.frame(mut_mat)
mut_mat_chr = mut_mat_df
mut_mat_chr[,1] <- as.character(mut_mat_chr[,1, drop = TRUE])
test_that("Non-numeric inputs give an error", {
    expect_error(cos_sim_matrix(mut_mat_chr, signatures))
})

test_that("Tibble inputs are converted into data.frames.", {
    output2 = cos_sim_matrix(tibble::as_tibble(mut_mat_df), signatures)
    expect_equal(output, output2)
})