Skip to content

Commit

Permalink
test(query): add tests for tabix
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespeapen committed Oct 18, 2024
1 parent ee96f8c commit e467973
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 8 additions & 0 deletions inst/extdata/tabix_dataframe.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"chr","start","end","beta","coverage"
"chr1",1,2,1.000,1
"chr1",3,4,1.000,1
"chr1",5,6,0.000,2
"chr1",7,8,0.000,1
"chr1",9,10,0.500,2
"chr1",11,12,1.000,2
"chr1",13,14,1.000,3
36 changes: 33 additions & 3 deletions tests/testthat/test-query.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
extdata <- system.file("extdata/test_chroms", package = "iscream")
bedfiles <- list.files(extdata, pattern = "*.bed.gz$", full.names = T)
library(data.table)
extdata <- system.file("extdata", package = "iscream")
chrom_beds <- list.files(paste0(extdata, "/test_chroms"), pattern = "*.bed.gz$", full.names = T)
tabix_beds <- list.files(extdata, pattern = "*.bed.gz$", full.names = T)
tabix_df_result <- list.files(extdata, pattern = "tabix_dataframe.test", full.names = T)
chrs <- sort(paste0("chr", c(seq(1:22), "M", "X", "Y")))
regions <- c(A = "chr1:1-6", B = "chr1:7-10", C = "chr1:11-14")

tabix_raw_res <- list(
`chr1:1-6` = c("chr1\t3\t4\t1.000\t2"),
`chr1:7-10` = c("chr1\t7\t8\t0.000\t2", "chr1\t9\t10\t1.000\t1"),
`chr1:11-14` = character(0)
)

test_that("query_chroms", {
expect_equal(
chrs,
query_chroms(bedfiles)
query_chroms(chrom_beds)
)
})

test_that("tabix dataframe", {
expect_equal(
tabix(tabix_beds[1], regions),
fread(tabix_df_result, colClasses = c("character", "integer", "integer", "numeric", "integer"))
)
})

test_that("tabix raw list", {
expect_equal(
tabix(tabix_beds[3], regions, raw = T),
tabix_raw_res
)
})

test_that("tabix dataframe", {
expect_warning(
tabix(chrom_beds[2], regions),
"No records found"
)
})

0 comments on commit e467973

Please sign in to comment.