tests/testthat/test-SeparatingMatrixToList.R

test_that("Testing SeparatingMatrixToList.R", {
  input_matrix <- Matrix::sparseMatrix(i = c(rep(1,4),2,2,2,3,3,3), j = c(1:4,1,2,3,2,3,4), x = c(1:3,1,1,2,3,3,2,1), 
                                       dims = c(4,4), dimnames = list(c("chrM_1_G_A", "chrM_2_A_G", "chrM_2_A_T", "chrM_4_C_G"), paste0("Cell_", 1:4)))
  test1 <- sigurd::SeparatingMatrixToList("chrM_1_G_A", input_matrix, remove_nocalls = FALSE)
  test2 <- sigurd::SeparatingMatrixToList("chrM_2_A_G", input_matrix, remove_nocalls = FALSE)
  test3 <- sigurd::SeparatingMatrixToList("chrM_2_A_T", input_matrix, remove_nocalls = FALSE)
  test4 <- sigurd::SeparatingMatrixToList("chrM_4_C_G", input_matrix, remove_nocalls = FALSE)
  test1_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_1_G_A", input_matrix, consensus = input_matrix, remove_nocalls = TRUE)
  test2_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_2_A_G", input_matrix, consensus = input_matrix, remove_nocalls = TRUE)
  test3_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_2_A_T", input_matrix, consensus = input_matrix, remove_nocalls = TRUE)
  test4_removed_nocalls <- sigurd::SeparatingMatrixToList("chrM_4_C_G", input_matrix, consensus = input_matrix, remove_nocalls = TRUE)
  # We generate the expected outputs.
  expected_result1 <- c(Cell_1 = 0, Cell_2 = 1, Cell_3 = 1, Cell_4 = 0)
  expected_result2 <- c(Cell_1 = 0, Cell_2 = 1, Cell_3 = 1, Cell_4 = 0)
  expected_result3 <- c(Cell_1 = 0, Cell_2 = 1, Cell_3 = 1, Cell_4 = 0)
  expected_result4 <- c(Cell_1 = 0, Cell_2 = 0, Cell_3 = 0, Cell_4 = 0)
  expected_result1_removed_nocalls <- c(Cell_1 = 0, Cell_2 = 1, Cell_3 = 1, Cell_4 = 0)
  expected_result2_removed_nocalls <- c(Cell_1 = 0, Cell_2 = 1, Cell_3 = 1)
  expected_result3_removed_nocalls <- c(Cell_2 = 1, Cell_3 = 1, Cell_4 = 0)
  expected_result4_removed_nocalls <- numeric()
  names(expected_result4_removed_nocalls) <- character()
  # We perform the tests.
  expect_equal(test1, expected_result1, tolerance = 1e-6)
  expect_equal(test2, expected_result2, tolerance = 1e-6)
  expect_equal(test3, expected_result3, tolerance = 1e-6)
  expect_equal(test4, expected_result4, tolerance = 1e-6)
  expect_equal(test1_removed_nocalls, expected_result1_removed_nocalls, tolerance = 1e-6)
  expect_equal(test2_removed_nocalls, expected_result2_removed_nocalls, tolerance = 1e-6)
  expect_equal(test3_removed_nocalls, expected_result3_removed_nocalls, tolerance = 1e-6)
  expect_equal(test4_removed_nocalls, expected_result4_removed_nocalls, tolerance = 1e-6)
})
CostaLab/sigurd documentation built on Feb. 10, 2025, 11:08 p.m.