Skip to content

Commit

Permalink
test(query): test tabix colnames - bismark, mergecg, colname warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespeapen committed Oct 18, 2024
1 parent 221a260 commit ee515fd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
Binary file added inst/extdata/biscuit_mergecg.bed.gz
Binary file not shown.
Binary file added inst/extdata/biscuit_mergecg.bed.gz.tbi
Binary file not shown.
8 changes: 8 additions & 0 deletions inst/extdata/tabix_dataframe_bismark.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"chr","start","end","methylation.percentage","count.methylated","count.unmethylated"
"chr1",1,1,100,1,0
"chr1",3,3,100,1,0
"chr1",5,5,0,0,2
"chr1",7,7,0,0,1
"chr1",9,9,50,1,1
"chr1",11,11,100,2,0
"chr1",13,13,100,3,0
59 changes: 55 additions & 4 deletions tests/testthat/test-query.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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)
biscuit_tabix_beds <- list.files(extdata, pattern = "[a|b|c|d].bed.gz$", full.names = T)
bismark_tabix_beds <- list.files(extdata, pattern = "[a|b|c|d].cov.gz$", full.names = T)
tabix_df_result <- list.files(extdata, pattern = "tabix_dataframe.test", full.names = T)
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)
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")

Expand All @@ -21,14 +24,18 @@ test_that("query_chroms", {

test_that("tabix dataframe", {
expect_equal(
tabix(tabix_beds[1], regions),
fread(tabix_df_result, colClasses = c("character", "integer", "integer", "numeric", "integer"))
tabix(biscuit_tabix_beds[1], regions),
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"))
)
})

test_that("tabix raw list", {
expect_equal(
tabix(tabix_beds[3], regions, raw = T),
tabix(biscuit_tabix_beds[3], regions, raw = T),
tabix_raw_res
)
})
Expand All @@ -39,3 +46,47 @@ test_that("tabix dataframe", {
"No records found"
)
})

test_that("tabix > 1 file", {
expect_error(
tabix(chrom_beds, regions),
"Cannot tabix multiple files - only single-file queries are currently supported"
)
})

custom_cols <- paste0("c", 1:5)
test_that("tabix custom colnames", {
expect_equal(
colnames(tabix(chrom_beds[1], regions, colnames = custom_cols)),
custom_cols
)
})

custom_cols <- paste0("c", 1:6)
test_that("tabix custom colnames too many", {
expect_warning(
tabix(chrom_beds[1], regions, colnames = custom_cols),
"Fewer columns in data than provided colnames"
)
})

custom_cols <- paste0("c", 1:4)
test_that("tabix custom colnames too few", {
expect_warning(
tabix(chrom_beds[1], regions, colnames = custom_cols),
paste("Did not use input 'colnames' - only", length(custom_cols), "names provided for 5 column data.table")
)
})


base_colnames <- c("chr", "start", "end")
biscuit_colnames <- c("beta", "coverage")
bismark_colnames <- c("methylation.percentage", "count.methylated", "count.unmethylated")
test_that("tabix mergecg colnames", {
expect_equal(
colnames(tabix(mergecg_bed, regions, aligner = "biscuit")),
c(base_colnames, biscuit_colnames, "mergecg")
)
})


0 comments on commit ee515fd

Please sign in to comment.