Skip to content

Commit

Permalink
test(utils): GRanges input to query_all, summarize_regions, tabix
Browse files Browse the repository at this point in the history
jamespeapen committed Nov 30, 2024
1 parent 6e185d8 commit bff131d
Showing 3 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/testthat/test-query_all.R
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ extdata <- system.file("extdata", package = "iscream")
biscuit_bedfiles <- list.files(extdata, pattern = "[a|b|c|d].bed.gz$", full.names = T)
bismark_bedfiles <- list.files(extdata, pattern = "[a|b|c|d].cov.gz$", full.names = T)
regions <- c(A = "chr1:1-6", B = "chr1:7-10", C = "chr1:11-14")
gr <- GenomicRanges::GRanges(regions)

M <- matrix(c(1, 0, 0, 1,
1, 0, 2, 2,
@@ -44,7 +45,14 @@ biscuit_test <- query_all(biscuit_bedfiles, regions, prealloc = 2)
bismark_test <- query_all(bismark_bedfiles, regions, aligner = "bismark")
biscuit_sparse_test <- query_all(biscuit_bedfiles, regions, sparse = T)
bismark_sparse_test <- query_all(bismark_bedfiles, regions, sparse = T, aligner = "bismark")
results <- list(biscuit_test, bismark_test, biscuit_sparse_test, bismark_sparse_test)
biscuit_granges_test <- query_all(biscuit_bedfiles, gr, prealloc = 2)
results <- list(
biscuit_test,
bismark_test,
biscuit_sparse_test,
bismark_sparse_test,
biscuit_granges_test
)

dense_class <- "matrix"
sparse_class <- "dgCMatrix"
@@ -68,6 +76,7 @@ test_that("matrix metadata", {
test_types(bismark_test, sparse = F)
test_types(biscuit_sparse_test, sparse = T)
test_types(bismark_sparse_test, sparse = T)
test_types(biscuit_granges_test, sparse = F)
})

test_content <- function(result_obj, sparse) {
@@ -86,6 +95,7 @@ test_content <- function(result_obj, sparse) {
}
test_that("matrix content", {
lapply(results[1:2], test_content, FALSE)
lapply(results[5], test_content, FALSE)
lapply(results[3:4], test_content, TRUE)
})

9 changes: 9 additions & 0 deletions tests/testthat/test-summarize_regions.R
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ extdata <- system.file("extdata", package = "iscream")
biscuit_bedfiles <- list.files(extdata, pattern = "[a|b|c|d].bed.gz$", full.names = TRUE)
bismark_bedfiles <- list.files(extdata, pattern = "[a|b|c|d].cov.gz$", full.names = TRUE)
regions <- c(A = "chr1:1-6", B = "chr1:7-10", C = "chr1:11-14")
gr <- GenomicRanges::GRanges(regions)
supported_funcs <- c("sum", "mean", "median", "stddev", "variance", "min", "max", "range")

# utils
@@ -166,6 +167,10 @@ test_that("summarize_regions 1 thread sum", {
m_sum,
summarize_regions(biscuit_bedfiles, regions, fun = "sum", mval = TRUE, nthreads = 1)
)
expect_equal(
m_sum,
summarize_regions(biscuit_bedfiles, gr, fun = "sum", mval = TRUE, nthreads = 1)
)
expect_equal(
beta_sum,
summarize_regions(biscuit_bedfiles, regions, fun = "sum", mval = FALSE, nthreads = 1)
@@ -234,6 +239,10 @@ test_that("summarize_regions 2 thread all bismark", {
m_all,
summarize_regions(bismark_bedfiles, regions, fun = "all", mval = TRUE, aligner = "bismark", nthreads = 2)
)
expect_equal(
m_all,
summarize_regions(bismark_bedfiles, gr, fun = "all", mval = TRUE, aligner = "bismark", nthreads = 2)
)
expect_equal(
beta_all,
summarize_regions(bismark_bedfiles, regions, fun = "all", mval = FALSE, aligner = "bismark", nthreads = 2)
5 changes: 5 additions & 0 deletions tests/testthat/test-tabix.R
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ tabix_df_result <- list.files(extdata, pattern = "tabix_dataframe.test", full.na
tabix_df_result_bismark <- list.files(extdata, pattern = "tabix_dataframe_bismark.test", full.names = T)
mergecg_bed <- list.files(extdata, pattern = "*_mergecg.bed.gz$", full.names = T)
regions <- c(A = "chr1:1-6", B = "chr1:7-10", C = "chr1:11-14")
gr <- GenomicRanges::GRanges(regions)

tabix_raw_res <- list(
`chr1:1-6` = c("chr1\t3\t4\t1.000\t2"),
@@ -19,6 +20,10 @@ test_that("tabix dataframe", {
tabix(biscuit_tabix_beds[1], regions),
fread(tabix_df_result, colClasses = c("character", "numeric", "numeric", "numeric", "numeric"))
)
expect_equal(
tabix(biscuit_tabix_beds[1], gr),
fread(tabix_df_result, colClasses = c("character", "numeric", "numeric", "numeric", "numeric"))
)
expect_equal(
tabix(bismark_tabix_beds[1], regions, aligner = 'bismark'),
fread(tabix_df_result_bismark, colClasses = c("character", "numeric", "numeric", "numeric", "numeric", "numeric"))

0 comments on commit bff131d

Please sign in to comment.