File: test-determine_regional_similarity.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 (70 lines) | stat: -rw-r--r-- 3,316 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
context("test-determine_regional_similarity")

# See the 'read_vcfs_as_granges()' example for how we obtained the
# following data:
grl <- readRDS(system.file("states/read_vcfs_as_granges_output.rds",
                           package = "MutationalPatterns"
))

# We pool all the variants together, because the function doesn't work well with a limited number of mutations.
# Still, in practice we recommend to use more mutations that in this example.
gr = unlist(grl)

# Specifiy the chromosomes of interest.
chromosomes <- names(genome(gr)[1:3])

# Load the corresponding reference genome.
ref_genome <- "BSgenome.Hsapiens.UCSC.hg19"
library(ref_genome, character.only = TRUE)

# Determine the regional similarities. Here we use a small window size to make the function work.
# In practice, we recommend a larger window size.
output = determine_regional_similarity(gr, ref_genome, chromosomes, window_size = 40, stepsize = 10, max_window_size_gen = 40000000)
output_oligo = determine_regional_similarity(gr, ref_genome, chromosomes[3], window_size = 60, stepsize = 60, oligo_correction = TRUE, max_window_size_gen = 40000000)
output_notexcl = determine_regional_similarity(gr, ref_genome, chromosomes, window_size = 40, stepsize = 10, exclude_self_mut_mat = FALSE, max_window_size_gen = 40000000)
output_smallext = determine_regional_similarity(gr, ref_genome, chromosomes, window_size = 40, stepsize = 10, extension = 0, max_window_size_gen = 40000000)
output_verbose = determine_regional_similarity(gr, ref_genome, chromosomes, window_size = 40, stepsize = 40, max_window_size_gen = 40000000, verbose = TRUE)

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

# Run tests
test_that("Output has correct class", {
  expect_true(inherits(output, c("region_cossim")))
  expect_true(inherits(output_oligo, c("region_cossim")))
  expect_true(inherits(output_notexcl, c("region_cossim")))
  expect_true(inherits(output_smallext, c("region_cossim")))
  expect_true(inherits(output_verbose, c("region_cossim")))
})

test_that("Output has correct dimensions", {
  expect_equal(dim(output@sim_tb), c(76, 8))
  expect_equal(dim(output@pos_tb), c(915, 3))
  expect_equal(dim(output_oligo@sim_tb), c(2, 10))
  expect_equal(dim(output_oligo@pos_tb), c(294, 3))
  expect_equal(dim(output_notexcl@sim_tb), c(76, 8))
  expect_equal(dim(output_notexcl@pos_tb), c(915, 3))
  expect_equal(dim(output_smallext@sim_tb), c(76, 8))
  expect_equal(dim(output_smallext@pos_tb), c(915, 3))
  expect_equal(dim(output_verbose@sim_tb), c(21, 8))
  expect_equal(dim(output_verbose@pos_tb), c(915, 3))
})

test_that("transforms correctly", {
  expect_equal(output@sim_tb, expected@sim_tb, check.attributes = FALSE)
  expect_equal(output@pos_tb, expected@pos_tb, check.attributes = FALSE)
})

test_that("exclude_self_mut_mat reduces cosine similarity", {
  expect_equal(sum(output@sim_tb$cossim > output_notexcl@sim_tb$cossim), 0)
})

test_that("oligonucleotide frequency correction increases cosine similarity", {
  expect_equal(sum(output_oligo@sim_tb$corrected_cossim < output_oligo@sim_tb$cossim), 0)
})

test_that("A smaller extension increases cosine similarity", {
  expect_equal(sum(output@sim_tb$cossim > output_smallext@sim_tb$cossim), 0)
})