2021-03-31 10:31:43 +02:00
|
|
|
context("Auxiliary functions to greedyMix")
|
|
|
|
|
|
2021-09-03 09:10:21 +02:00
|
|
|
# Defining the relative path to current inst -----------------------------------
|
2023-08-09 10:54:48 +02:00
|
|
|
path_inst <- system.file("extdata", "", package = "rBAPS")
|
2021-09-03 09:10:21 +02:00
|
|
|
|
|
|
|
|
# Reading datasets -------------------------------------------------------------
|
2021-03-31 10:31:43 +02:00
|
|
|
baps_diploid <- read.delim(
|
2023-08-09 10:54:48 +02:00
|
|
|
file = file.path(path_inst, "BAPS_format_clustering_diploid.txt"),
|
2021-11-10 14:02:35 +01:00
|
|
|
sep = " ",
|
|
|
|
|
header = FALSE
|
2021-03-31 10:31:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
test_that("handleData works as expected", {
|
2021-11-10 14:02:35 +01:00
|
|
|
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(
|
2021-11-10 14:02:35 +01:00
|
|
|
data = file.path(path_inst, "FASTA_clustering_haploid.fasta"),
|
|
|
|
|
format = "FASTA"
|
2021-09-03 11:10:06 +02:00
|
|
|
)
|
2023-09-11 13:14:23 +02:00
|
|
|
raw_vcf <- importFile(
|
2021-11-10 14:02:35 +01:00
|
|
|
data = file.path(path_inst, "vcf_example.vcf"),
|
|
|
|
|
format = "VCF",
|
|
|
|
|
verbose = FALSE
|
2021-09-03 09:10:21 +02:00
|
|
|
)
|
2023-09-11 13:53:42 +02:00
|
|
|
raw_bam <- importFile(
|
2021-11-10 14:02:35 +01:00
|
|
|
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
|
|
|
|
2021-09-03 09:10:21 +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))
|
2021-11-10 14:02:35 +01:00
|
|
|
expect_error(
|
2023-09-11 13:14:23 +02:00
|
|
|
importFile(
|
2021-11-10 14:02:35 +01:00
|
|
|
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)
|
2021-09-03 09:10:21 +02:00
|
|
|
})
|
2020-07-31 13:59:30 +02:00
|
|
|
|
2023-09-11 13:14:23 +02:00
|
|
|
df_fasta <- greedyMix(
|
|
|
|
|
data = file.path(path_inst, "FASTA_clustering_haploid.fasta"),
|
|
|
|
|
format = "FASTA"
|
|
|
|
|
)
|
|
|
|
|
test_that("greedyMix() works", {
|
|
|
|
|
expect_error(greedyMix(file.path(path_inst, "vcf_example.vcf")))
|
|
|
|
|
expect_error(greedyMix(file.path(path_inst, "bam_example.bam")))
|
|
|
|
|
})
|
|
|
|
|
|
2020-07-31 13:59:30 +02:00
|
|
|
context("Linkage")
|
|
|
|
|
|
|
|
|
|
test_that("Linkages are properly calculated", {
|
2021-11-10 14:02:35 +01:00
|
|
|
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)
|
|
|
|
|
)
|
2021-09-03 09:10:21 +02:00
|
|
|
})
|