Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zilong-Li committed Sep 10, 2024
1 parent fe4b9be commit 5a5ec56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/vcf-compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#' test <- system.file("extdata", "imputed.gt.vcf.gz", package="vcfppR")
#' truth <- system.file("extdata", "imputed.gt.vcf.gz", package="vcfppR")
#' samples <- "HG00133,HG00143,HG00262"
#' res <- vcfcomp(test, truth, stats="f1", format=c('GT','GT'), samples=samples)
#' res <- vcfcomp(test, truth, stats="f1", format=c('GT','GT'), samples=samples, setid=TRUE)
#' str(res)
#' @export
vcfcomp <- function(test, truth,
Expand Down
15 changes: 10 additions & 5 deletions tests/testthat/test-vcf-comp.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ imputedvcf <- system.file("extdata", "imputed.gt.vcf.gz", package="vcfppR")
test_that("can work for correlation r2 between DS and GT", {
skip_on_os(c("windows"), arch = NULL)
samples <- "HG00673,NA10840"
res <- vcfcomp(imputedvcf, imputedvcf, bins = c(0,1), by.sample = TRUE, samples = samples, stats = "all")
res <- vcfcomp(imputedvcf, imputedvcf, bins = c(0,1),
by.sample = TRUE, samples = samples, stats = "all",
setid = TRUE)
expect_equal(as.numeric(res$r2[1,]), c(15, 6, 1), tolerance=1e-6)
expect_identical(unlist(res$f1[[3]]), rep(1,2))
expect_identical(unlist(res$nrc[[3]]), rep(1,2))
Expand All @@ -20,30 +22,33 @@ test_that("can work for r2 with af", {
names(af) <- d1$id
affile <- tempfile()
saveRDS(af, affile)
res <- vcfcomp(imputedvcf, rawvcf, stats = "r2", bins = c(0,1), af = affile, samples = samples)
res <- vcfcomp(imputedvcf, rawvcf, stats = "r2", bins = c(0,1),
af = affile, samples = samples, setid = TRUE)
expect_identical(res[[2]][,3], 1)
})

test_that("can work for F1 score", {
skip_on_os(c("windows"), arch = NULL)
samples <- "HG00673,NA10840"
res <- vcfcomp(rawvcf, imputedvcf, stats = "f1", samples = samples, by.sample = TRUE, bins = c(0,1))
res <- vcfcomp(rawvcf, imputedvcf, stats = "f1", samples = samples,
by.sample = TRUE, bins = c(0,1), setid = TRUE)
expect_identical(paste0(res$samples, collapse = ","), samples)
expect_identical(unlist(res[[2]][[3]]), rep(1,2))
})

test_that("can work for NRC rate by sample", {
skip_on_os(c("windows"), arch = NULL)
samples <- "HG00673,NA10840"
res <- vcfcomp(rawvcf, imputedvcf, stats = "nrc", samples = samples, by.sample = TRUE, bins = c(0,1))
res <- vcfcomp(rawvcf, imputedvcf, stats = "nrc", samples = samples,
by.sample = TRUE, bins = c(0,1), setid = TRUE)
expect_identical(paste0(res$samples, collapse = ","), samples)
expect_identical(unlist(res[[2]][[3]]), rep(1,2))
})

test_that("can work for PSE", {
skip_on_os(c("windows"), arch = NULL)
samples <- "HG00151,HG00380"
(res <- vcfcomp(imputedvcf, imputedvcf, stats = "pse", samples = samples))
(res <- vcfcomp(imputedvcf, imputedvcf, stats = "pse", samples = samples, setid = TRUE))
expect_true(is.nan(res[[2]][[1]]$pse))
expect_true((res[[2]][[2]]$pse==0))
expect_true((res[[2]][[2]]$disc==0))
Expand Down

0 comments on commit 5a5ec56

Please sign in to comment.