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 -----------------------------------
|
2021-08-23 08:34:28 +02:00
|
|
|
if (interactive()) {
|
2021-09-03 09:10:21 +02:00
|
|
|
path_inst <- "../../inst/ext"
|
2021-08-23 08:34:28 +02:00
|
|
|
} else {
|
2021-09-03 09:10:21 +02:00
|
|
|
path_inst <- system.file("ext", "", package="rBAPS")
|
2021-08-23 08:34:28 +02:00
|
|
|
}
|
2021-09-03 09:10:21 +02:00
|
|
|
|
|
|
|
|
# Reading datasets -------------------------------------------------------------
|
2021-03-31 10:31:43 +02:00
|
|
|
baps_diploid <- read.delim(
|
2021-09-03 09:10:21 +02:00
|
|
|
file = paste(path_inst, "BAPS_format_clustering_diploid.txt", sep="/"),
|
2021-03-31 10:31:43 +02:00
|
|
|
sep = " ",
|
|
|
|
|
header = FALSE
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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-09-03 09:10:21 +02:00
|
|
|
context("Opening files on greedyMix")
|
2020-06-24 11:48:23 +02:00
|
|
|
|
2021-09-03 09:10:21 +02:00
|
|
|
df_fasta <- greedyMix(
|
|
|
|
|
data = paste(path_inst, "FASTA_clustering_haploid.fasta", sep="/"),
|
|
|
|
|
format ="fasta"
|
|
|
|
|
)
|
2021-09-03 09:14:52 +02:00
|
|
|
# TODO #17: add example reading VCF
|
|
|
|
|
# TODO #18: add example reading SAM
|
|
|
|
|
# TODO #19: add example reading Genpop
|
2021-09-03 09:10:21 +02:00
|
|
|
test_that("Files are imported correctly", {
|
|
|
|
|
expect_equal(dim(df_fasta), c(5, 99))
|
|
|
|
|
})
|
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)
|
|
|
|
|
)
|
2021-09-03 09:10:21 +02:00
|
|
|
})
|