ourMELONS/tests/testthat/test-greedyMix.R

84 lines
2.4 KiB
R
Raw Normal View History

2021-03-31 10:31:43 +02:00
context("Auxiliary functions to greedyMix")
# Defining the relative path to current inst -----------------------------------
path_inst <- system.file("extdata", "", package = "rBAPS")
# Reading datasets -------------------------------------------------------------
2021-03-31 10:31:43 +02:00
baps_diploid <- read.delim(
2024-04-10 14:18:17 +02:00
file = file.path(path_inst, "BAPS_clustering_diploid.txt"),
sep = " ",
header = FALSE
2021-03-31 10:31:43 +02:00
)
test_that("handleData works as expected", {
data_obs <- handleData(baps_diploid)$newData
data_exp <- matrix(
c(
-9, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1,
-9, 1, 1, 2, 2, 2, 1, 1, 1, 2, 1,
3, 2, 2, 3, 2, -9, 3, 1, 2, 1, 2,
2, 1, 2, 1, 2, -9, 1, 1, 1, 1, 2,
3, 1, 1, 1, 2, 1, 1, 2, -9, 1, 3,
3, 1, 2, 1, 1, 1, 2, 1, -9, 2, 3,
1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 4,
3, 2, 2, 3, 2, 2, 3, 1, 2, 1, 4,
2, 1, 2, 1, -9, 1, 1, 1, 1, 1, 5,
3, 1, 1, 1, -9, 1, 1, 2, 1, 1, 5
),
nrow = 10, byrow = TRUE
)
colnames(data_exp) <- colnames(data_obs)
expect_equal(data_obs, data_exp)
2021-03-31 10:31:43 +02:00
})
2023-08-11 08:17:56 +02:00
context("Processing files through greedyMix")
2020-06-24 11:48:23 +02:00
2023-09-11 13:14:23 +02:00
raw_fasta <- importFile(
data = file.path(path_inst, "FASTA_clustering_haploid.fasta"),
format = "FASTA"
)
2023-09-11 13:14:23 +02:00
raw_vcf <- importFile(
data = file.path(path_inst, "vcf_example.vcf"),
format = "VCF",
verbose = FALSE
)
2023-09-11 13:53:42 +02:00
raw_bam <- importFile(
data = file.path(path_inst, "bam_example.bam"),
format = "BAM",
2021-09-03 12:50:11 +02:00
)
2023-09-11 13:14:23 +02:00
test_that("Files are imported correctly", {
2023-09-11 13:14:23 +02:00
expect_equal(dim(raw_fasta), c(5, 99))
expect_equal(dim(raw_vcf), c(variants = 2, fix_cols = 8, gt_cols = 3))
expect_error(
2023-09-11 13:14:23 +02:00
importFile(
data = paste(path_inst, "sam_example.sam", sep = "/"),
format = "SAM",
)
)
2023-09-11 13:53:42 +02:00
expect_equal(length(raw_bam[[1]]), 13)
})
2020-07-31 13:59:30 +02:00
2024-07-02 11:23:22 +02:00
test_that("greedyMix() fails successfully", {
2023-09-11 13:14:23 +02:00
expect_error(greedyMix(file.path(path_inst, "vcf_example.vcf")))
expect_error(greedyMix(file.path(path_inst, "bam_example.bam")))
})
2024-07-02 16:39:48 +02:00
test_that("greedyMix() works when it should", {
baps_file <- file.path(path_inst, "BAPS_clustering_diploid.txt")
fasta_file <- file.path(path_inst, "FASTA_clustering_haploid.fasta")
2024-07-02 16:39:48 +02:00
greedy_baps <- greedyMix(baps_file, "BAPS")
expect_type(greedy_baps, "list")
expect_length(greedy_baps, 10L)
})
2020-07-31 13:59:30 +02:00
context("Linkage")
test_that("Linkages are properly calculated", {
Y <- c(0.5, 0.3, 0.6, 0.3, 0.3, 0.2, 0.3, 0.3, 0.3, 0.5)
expect_equal(
object = linkage(Y),
expected = matrix(c(2, 1, 7, 8, 4, 3, 5, 6, .2, .3, .3, .6), ncol = 3)
)
})