Skip to content

Commit 95e6d04

Browse files
bschilderclaude
andcommitted
Add 30 test files covering ~60 functions, coverage 45% -> ~60%
Tests for data position helpers, find_top_consensus, order_loci, snps_by_mutation_type, bigwig metadata, save_annotations, select_genome, GRanges helpers (clean/rbind/filter/overlap), chromatin state filtering, XGR foreground/background/enrichment, ROADMAP annotate/merge, NOTT2019 markers/promoters/data, CORCES2020 data accessors, GOSHIFTER utilities, CS plots, standardize_celltypes, haplor summary, window_limits. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ccdf6c8 commit 95e6d04

30 files changed

Lines changed: 1677 additions & 0 deletions
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
test_that("get_CORCES2020_scATACseq_celltype_peaks returns data.table", {
2+
skip_if_offline()
3+
dat <- echoannot::get_CORCES2020_scATACseq_celltype_peaks()
4+
expect_true(data.table::is.data.table(dat))
5+
expect_true(nrow(dat) > 0)
6+
expect_true("hg38_Chromosome" %in% colnames(dat))
7+
expect_true("hg38_Start" %in% colnames(dat))
8+
expect_true("hg38_Stop" %in% colnames(dat))
9+
})
10+
11+
test_that("get_CORCES2020_bulkATACseq_peaks returns data.table", {
12+
skip_if_offline()
13+
dat <- echoannot::get_CORCES2020_bulkATACseq_peaks()
14+
expect_true(data.table::is.data.table(dat))
15+
expect_true(nrow(dat) > 0)
16+
expect_true("hg38_Chromosome" %in% colnames(dat))
17+
})
18+
19+
test_that("get_CORCES2020_scATACseq_peaks returns data.table", {
20+
skip_if_offline()
21+
dat <- echoannot::get_CORCES2020_scATACseq_peaks()
22+
expect_true(data.table::is.data.table(dat))
23+
expect_true(nrow(dat) > 0)
24+
})
25+
26+
test_that("get_CORCES2020_cicero_coaccessibility returns data.table", {
27+
skip_if_offline()
28+
dat <- echoannot::get_CORCES2020_cicero_coaccessibility()
29+
expect_true(data.table::is.data.table(dat))
30+
expect_true(nrow(dat) > 0)
31+
expect_true("Coaccessibility" %in% colnames(dat))
32+
})
33+
34+
test_that("get_CORCES2020_hichip_fithichip_loop_calls returns data.table", {
35+
skip_if_offline()
36+
dat <- echoannot::get_CORCES2020_hichip_fithichip_loop_calls()
37+
expect_true(data.table::is.data.table(dat))
38+
expect_true(nrow(dat) > 0)
39+
})

tests/testthat/test-CS_plots.R

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
test_that("CS_bin_plot creates plot and data", {
2+
dat <- echodata::BST1
3+
dat$Locus <- "BST1"
4+
result <- suppressWarnings(
5+
echoannot::CS_bin_plot(merged_DT = dat, show_plot = FALSE)
6+
)
7+
expect_true(is.list(result))
8+
expect_true("plot" %in% names(result))
9+
expect_true("data" %in% names(result))
10+
expect_true(methods::is(result$plot, "ggplot"))
11+
expect_true(nrow(result$data) > 0)
12+
})
13+
14+
test_that("CS_counts_plot creates plot and data", {
15+
dat <- echodata::BST1
16+
dat$Locus <- "BST1"
17+
result <- suppressWarnings(
18+
echoannot::CS_counts_plot(merged_DT = dat, show_plot = FALSE)
19+
)
20+
expect_true(is.list(result))
21+
expect_true("plot" %in% names(result))
22+
expect_true("data" %in% names(result))
23+
expect_true(methods::is(result$plot, "ggplot"))
24+
})
25+
26+
test_that("CS_counts_plot with show_numbers=FALSE", {
27+
dat <- echodata::BST1
28+
dat$Locus <- "BST1"
29+
result <- suppressWarnings(
30+
echoannot::CS_counts_plot(
31+
merged_DT = dat,
32+
show_numbers = FALSE,
33+
show_plot = FALSE
34+
)
35+
)
36+
expect_true(methods::is(result$plot, "ggplot"))
37+
})
38+
39+
test_that("CS_counts_plot label_yaxis=FALSE works", {
40+
dat <- echodata::BST1
41+
dat$Locus <- "BST1"
42+
result <- suppressWarnings(
43+
echoannot::CS_counts_plot(
44+
merged_DT = dat,
45+
label_yaxis = FALSE,
46+
show_plot = FALSE
47+
)
48+
)
49+
expect_true(methods::is(result$plot, "ggplot"))
50+
})
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
test_that("GOSHIFTER_search_ROADMAP filters by EID", {
2+
ref_path <- system.file(
3+
"extdata/ROADMAP",
4+
"ROADMAP_Epigenomic.js",
5+
package = "echoannot"
6+
)
7+
## Get all entries first to find a valid EID
8+
all_ref <- echoannot:::GOSHIFTER_search_ROADMAP(
9+
Roadmap_reference = ref_path,
10+
verbose = FALSE
11+
)
12+
valid_eid <- all_ref$EID[1]
13+
14+
result <- echoannot:::GOSHIFTER_search_ROADMAP(
15+
Roadmap_reference = ref_path,
16+
EID_filter = valid_eid,
17+
verbose = FALSE
18+
)
19+
expect_true(nrow(result) >= 1)
20+
expect_true(all(result$EID == valid_eid))
21+
})
22+
23+
test_that("GOSHIFTER_search_ROADMAP filters by GROUP", {
24+
ref_path <- system.file(
25+
"extdata/ROADMAP",
26+
"ROADMAP_Epigenomic.js",
27+
package = "echoannot"
28+
)
29+
all_ref <- echoannot:::GOSHIFTER_search_ROADMAP(
30+
Roadmap_reference = ref_path,
31+
verbose = FALSE
32+
)
33+
valid_group <- all_ref$GROUP[1]
34+
35+
result <- echoannot:::GOSHIFTER_search_ROADMAP(
36+
Roadmap_reference = ref_path,
37+
GROUP_filter = valid_group,
38+
verbose = FALSE
39+
)
40+
expect_true(nrow(result) >= 1)
41+
expect_true(all(result$GROUP == valid_group))
42+
})
43+
44+
test_that("GOSHIFTER_find_folder errors when NULL and echolocatoR not installed", {
45+
## The NULL path relies on echolocatoR being installed
46+
## If echolocatoR is not installed, this should error
47+
skip_if(
48+
nzchar(system.file("tools/goshifter", package = "echolocatoR")),
49+
"echolocatoR has GoShifter bundled - skip this test"
50+
)
51+
expect_error(
52+
echoannot:::GOSHIFTER_find_folder(goshifter = NULL),
53+
"GoShifter directory not found"
54+
)
55+
})
56+
57+
test_that("GOSHIFTER_list_chromatin_states uses custom annotations_path", {
58+
## Test with the default package path explicitly
59+
result <- echoannot:::GOSHIFTER_list_chromatin_states(
60+
annotations_path = NULL
61+
)
62+
expect_true(data.table::is.data.table(result))
63+
expect_true(nrow(result) > 0)
64+
})
65+
66+
test_that("GOSHIFTER_bed_names with single EID", {
67+
ref <- data.table::data.table(EID = "E099")
68+
result <- echoannot:::GOSHIFTER_bed_names(RM_ref = ref)
69+
expect_length(result, 1)
70+
expect_true(grepl("^E099", result))
71+
expect_true(grepl("\\.bed\\.gz$", result))
72+
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
test_that("get_NOTT2019_interactome returns named list", {
2+
skip_if_offline()
3+
dat <- echoannot:::get_NOTT2019_interactome()
4+
expect_true(is.list(dat))
5+
expect_true(length(dat) > 0)
6+
expect_true(!is.null(names(dat)))
7+
## Should contain sheets with promoter/enhancer/interactome
8+
has_promoter <- any(grepl("promoter", names(dat), ignore.case = TRUE))
9+
has_enhancer <- any(grepl("enhancer", names(dat), ignore.case = TRUE))
10+
has_interactome <- any(grepl("interactome", names(dat), ignore.case = TRUE))
11+
expect_true(has_promoter || has_enhancer || has_interactome)
12+
})
13+
14+
test_that("get_NOTT2019_superenhancer_interactome returns data.table", {
15+
skip_if_offline()
16+
dat <- echoannot::get_NOTT2019_superenhancer_interactome()
17+
expect_true(data.table::is.data.table(dat))
18+
expect_true(nrow(dat) > 0)
19+
expect_true("chr" %in% colnames(dat))
20+
})
21+
22+
test_that("NOTT2019_get_regulatory_regions returns data.frame", {
23+
skip_if_offline()
24+
regions <- echoannot::NOTT2019_get_regulatory_regions(
25+
as_granges = FALSE,
26+
verbose = FALSE
27+
)
28+
expect_true(is.data.frame(regions))
29+
expect_true(nrow(regions) > 0)
30+
expect_true("Cell_type" %in% colnames(regions))
31+
expect_true("Element" %in% colnames(regions))
32+
## Cell_type should be standardized
33+
valid_celltypes <- c("astrocytes", "neurons", "oligo", "microglia")
34+
expect_true(all(regions$Cell_type %in% valid_celltypes))
35+
})
36+
37+
test_that("NOTT2019_get_regulatory_regions as_granges returns GRanges", {
38+
skip_if_offline()
39+
regions <- echoannot::NOTT2019_get_regulatory_regions(
40+
as_granges = TRUE,
41+
verbose = FALSE
42+
)
43+
expect_true(methods::is(regions, "GRanges"))
44+
expect_true(length(regions) > 0)
45+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
test_that("NOTT2019_get_promoter_celltypes identifies active promoters", {
2+
## Create mock data resembling the NOTT2019 interactome data
3+
annot_sub <- data.frame(
4+
PU1_active_promoter = c(1, 0, 1),
5+
NeuN_active_promoter = c(0, 1, 0),
6+
Olig2_active_promoter = c(0, 0, 0),
7+
LHX2_active_promoter = c(1, 1, 0)
8+
)
9+
marker_key <- echoannot:::NOTT2019_marker_key()
10+
11+
result <- echoannot:::NOTT2019_get_promoter_celltypes(
12+
annot_sub = annot_sub,
13+
marker_key = marker_key,
14+
verbose = FALSE
15+
)
16+
expect_true(is.character(result))
17+
## PU1 -> microglia, NeuN -> neurons, LHX2 -> astrocytes are all active
18+
expect_true(grepl("microglia", result))
19+
expect_true(grepl("neurons", result))
20+
expect_true(grepl("astrocytes", result))
21+
## Olig2 column sums to 0, so oligo should not appear
22+
expect_false(grepl("oligo", result))
23+
})
24+
25+
test_that("NOTT2019_get_promoter_celltypes returns empty string when none active", {
26+
annot_sub <- data.frame(
27+
PU1_active_promoter = c(0, 0),
28+
NeuN_active_promoter = c(0, 0),
29+
Olig2_active_promoter = c(0, 0),
30+
LHX2_active_promoter = c(0, 0)
31+
)
32+
marker_key <- echoannot:::NOTT2019_marker_key()
33+
34+
result <- echoannot:::NOTT2019_get_promoter_celltypes(
35+
annot_sub = annot_sub,
36+
marker_key = marker_key,
37+
verbose = FALSE
38+
)
39+
expect_true(is.character(result))
40+
expect_equal(result, "")
41+
})
42+
43+
test_that("NOTT2019_bigwig_metadata is available as package data", {
44+
data("NOTT2019_bigwig_metadata", package = "echoannot")
45+
expect_true(exists("NOTT2019_bigwig_metadata"))
46+
expect_true(is.data.frame(NOTT2019_bigwig_metadata))
47+
expect_true(nrow(NOTT2019_bigwig_metadata) > 0)
48+
expect_true("name" %in% colnames(NOTT2019_bigwig_metadata) ||
49+
"data_link" %in% colnames(NOTT2019_bigwig_metadata))
50+
})
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
test_that("ROADMAP_annotate adds Source column to GRanges list", {
2+
## Create a simple GRanges list with EID metadata
3+
gr1 <- GenomicRanges::GRanges(
4+
seqnames = c("chr1", "chr1"),
5+
ranges = IRanges::IRanges(start = c(100, 200), end = c(150, 250))
6+
)
7+
GenomicRanges::mcols(gr1)$EID <- "E003"
8+
GenomicRanges::mcols(gr1)$name <- "test"
9+
10+
grlist <- list(item1 = gr1)
11+
12+
## Get the ROADMAP reference to find a valid EID
13+
ref <- echoannot::ROADMAP_construct_reference(verbose = FALSE)
14+
15+
result <- echoannot:::ROADMAP_annotate(
16+
grlist = grlist,
17+
ref = ref,
18+
verbose = FALSE
19+
)
20+
expect_true(is.list(result))
21+
expect_true(length(result) == 1)
22+
gr_out <- result[[1]]
23+
expect_true("Source" %in% colnames(GenomicRanges::mcols(gr_out)))
24+
})
25+
26+
test_that("ROADMAP_annotate uses keyword_query when ref is NULL", {
27+
gr1 <- GenomicRanges::GRanges(
28+
seqnames = "chr1",
29+
ranges = IRanges::IRanges(start = 100, end = 200)
30+
)
31+
## Use a real EID that exists in the reference
32+
ref <- echoannot::ROADMAP_construct_reference(verbose = FALSE)
33+
real_eid <- ref$EID[1]
34+
GenomicRanges::mcols(gr1)$EID <- real_eid
35+
GenomicRanges::mcols(gr1)$name <- "test"
36+
37+
grlist <- list(item1 = gr1)
38+
result <- echoannot:::ROADMAP_annotate(
39+
grlist = grlist,
40+
ref = NULL,
41+
keyword_query = NULL,
42+
verbose = FALSE
43+
)
44+
expect_true(is.list(result))
45+
gr_out <- result[[1]]
46+
expect_true("Source" %in% colnames(GenomicRanges::mcols(gr_out)))
47+
})
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
test_that("ROADMAP_merge_and_process merges and filters", {
2+
## Create a GRangesList with Source metadata
3+
gr1 <- GenomicRanges::GRanges(
4+
seqnames = c("chr4", "chr4", "chr4"),
5+
ranges = IRanges::IRanges(
6+
start = c(15723865, 15737348, 15750000),
7+
end = c(15724000, 15737500, 15751000)
8+
)
9+
)
10+
GenomicRanges::mcols(gr1)$name <- c("1_TssA", "2_Enh", "3_Quies")
11+
GenomicRanges::mcols(gr1)$EID <- "E001"
12+
GenomicRanges::mcols(gr1)$Source <- "Brain_Tissue"
13+
14+
grl <- GenomicRanges::GRangesList(test = gr1)
15+
16+
## Use BST1 as the query
17+
gr_snp <- echodata::BST1
18+
19+
result <- echoannot:::ROADMAP_merge_and_process(
20+
grl.roadmap = grl,
21+
gr.snp = gr_snp,
22+
n_top = NULL,
23+
verbose = FALSE
24+
)
25+
expect_true(methods::is(result, "GRanges"))
26+
})
27+
28+
test_that("ROADMAP_merge_and_process n_top limits sources", {
29+
## Create GRanges with multiple sources
30+
gr1 <- GenomicRanges::GRanges(
31+
seqnames = rep("chr4", 5),
32+
ranges = IRanges::IRanges(
33+
start = seq(15723865, 15724265, 100),
34+
end = seq(15724865, 15725265, 100)
35+
)
36+
)
37+
GenomicRanges::mcols(gr1)$Source <- "SourceA"
38+
GenomicRanges::mcols(gr1)$name <- paste0("1_TssA")
39+
40+
gr2 <- GenomicRanges::GRanges(
41+
seqnames = rep("chr4", 2),
42+
ranges = IRanges::IRanges(
43+
start = c(15723865, 15723965),
44+
end = c(15724865, 15724965)
45+
)
46+
)
47+
GenomicRanges::mcols(gr2)$Source <- "SourceB"
48+
GenomicRanges::mcols(gr2)$name <- paste0("2_Enh")
49+
50+
grl <- GenomicRanges::GRangesList(a = gr1, b = gr2)
51+
gr_snp <- echodata::BST1
52+
53+
result <- echoannot:::ROADMAP_merge_and_process(
54+
grl.roadmap = grl,
55+
gr.snp = gr_snp,
56+
n_top = 1,
57+
verbose = FALSE
58+
)
59+
expect_true(methods::is(result, "GRanges"))
60+
## Should only keep the top source
61+
expect_true(length(unique(result$Source)) <= 1)
62+
})

0 commit comments

Comments
 (0)