Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zilong-Li committed Dec 27, 2024
1 parent 2cf25a6 commit e732c66
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Binary file added inst/extdata/test.bcf
Binary file not shown.
Binary file added inst/extdata/test.bcf.csi
Binary file not shown.
13 changes: 12 additions & 1 deletion tests/testthat/test-vcf-reader.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library(testthat)

bcffile <- system.file("extdata", "test.bcf", package="vcfppR")
vcffile <- system.file("extdata", "raw.gt.vcf.gz", package="vcfppR")
svfile <- system.file("extdata", "sv.vcf.gz", package="vcfppR")

Expand Down Expand Up @@ -268,4 +269,14 @@ test_that("can set region back and forth", {

})


test_that("bcfreader: subset samples and region for BCF", {
br <- vcfreader$new(bcffile, "1:10000-13000", "I1,I10")
expect_true(br$variant())
expect_identical(br$genotypes(F), c(1L, 1L, 0L, 1L))
expect_true(br$variant())
expect_identical(br$genotypes(F), c(0L, 0L, 0L, 0L))
expect_true(br$variant())
expect_identical(br$genotypes(F), c(1L, 0L, 0L, 0L))
expect_true(br$variant())
expect_identical(br$genotypes(F), c(1L, 1L, 0L, 1L))
})
7 changes: 7 additions & 0 deletions tests/testthat/test-vcf-table.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library(testthat)

bcffile <- system.file("extdata", "test.bcf", package="vcfppR")
vcffile <- system.file("extdata", "raw.gt.vcf.gz", package="vcfppR")
svfile <- system.file("extdata", "sv.vcf.gz", package="vcfppR")

Expand Down Expand Up @@ -76,3 +77,9 @@ test_that("extract EV (String, number=1) from sv file", {
test_that("query a non-existing region", {
expect_error(res <- vcftable(vcffile, region = "chr14:0-1000"))
})

test_that("subset samples and region for BCF", {
res <- vcftable(bcffile, region = "1:10000-13000", samples = "I1,I30", vartype = "snps", format = "DS")
m <- matrix(c(2.000, 2.000, 0.195, 0.000, 1.000, 0.000, 2.000, 0.036), byrow = TRUE, ncol = 2)
expect_equal(res[[10]], m, tolerance = 1e6)
})

0 comments on commit e732c66

Please sign in to comment.