Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timoast committed Jan 16, 2025
1 parent 6a720d5 commit 1eb526c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 48 deletions.
47 changes: 24 additions & 23 deletions tests/testthat/test-motifs.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ pwm <- readRDS("../testdata/pwm_2motifs.rds")
genome.fasta <- system.file("extdata", "chr1_start.fa", package = "Signac")
genome <- Rsamtools::FaFile(genome.fasta)

# Cannot be tested if motifmatchr is not a dependency
# test_that("AddMotifs works", {
# motif <- AddMotifs(
# atac_small[["peaks"]],
# genome,
# pwm,
# verbose = FALSE
# )
# expect_equal(dim(Motifs(motif)), c(323, 2))
# })

test_that("AddMotifs works", {
skip_if_not_installed("motifmatchr")
motif <- AddMotifs(
atac_small[["peaks"]],
genome,
pwm,
verbose = FALSE
)
expect_equal(dim(Motifs(motif)), c(323, 2))
})

test_that("AddMotifs works with fakechr", {
fpath <- system.file("extdata", "fragments.tsv.gz", package = "Signac")
Expand All @@ -29,35 +30,35 @@ test_that("AddMotifs works with fakechr", {
keep_all_features = TRUE,
verbose = FALSE
)
object <- CreateChromatinAssay(
expect_warning(object <- CreateChromatinAssay(
counts = mat,
sep = c(":", "-"),
fragments = fragments,
verbose = FALSE
)
# This requires motifmatchr
# motif <- AddMotifs.default(
# granges(object)[100:nrow(object)],
# genome,
# pwm,
# verbose = FALSE
# )
))
skip_if_not_installed("motifmatchr")
motif <- suppressWarnings(AddMotifs(
granges(object)[100:nrow(object)],
genome,
pwm,
verbose = FALSE
))
motif <- readRDS("../testdata/motifObj_2_225.rds")
expect_equal(dim(motif), c(225, 2))
test <- SetAssayData(
expect_warning(test <- SetAssayData(
object = object,
layer = "motifs",
new.data = motif,
verbose = FALSE
)
))
expect_equal(dim(Motifs(test)), c(324, 2))
# If some features are not in the ChromatinAssay
# They should be removed
test <- SetAssayData(
expect_warning(test <- SetAssayData(
object = atac_small,
layer = "motifs",
new.data = motif,
verbose = FALSE
)
))
expect_equal(dim(Motifs(test)), c(323, 2))
})
53 changes: 28 additions & 25 deletions tests/testthat/test-preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,31 @@ test_that("NucleosomeSignal works", {
expected = c(NaN, NaN, 0.0, 2.5, NaN, NaN)
)
})
# Cannot be tested if motifmatchr is not a dependency
# test_that("CreateMotifMatrix works", {
# pwm <- readRDS("../testdata/pwm_2motifs.rds")
# genome.fasta <- system.file("extdata", "chr1_start.fa", package = "Signac")
# genome <- Rsamtools::FaFile(genome.fasta)
# motif.matrix <- CreateMotifMatrix(
# features = granges(atac_small),
# pwm = pwm,
# genome = genome
# )
# expect_equal(dim(motif.matrix), c(323, 2))
# features <- suppressWarnings(c(
# granges(atac_small),
# GenomicRanges::GRanges(
# seqnames = "fake_chr",
# ranges = IRanges::IRanges(start = 1, end = 1000)
# )
# ))
# motif.matrix <- CreateMotifMatrix(
# features = features,
# pwm = pwm,
# genome = BSgenome.Hsapiens.UCSC.hg19
# )
# expect_equal(dim(motif.matrix), c(324, 2))
# })


test_that("CreateMotifMatrix works", {
pwm <- readRDS("../testdata/pwm_2motifs.rds")
genome.fasta <- system.file("extdata", "chr1_start.fa", package = "Signac")
genome <- Rsamtools::FaFile(genome.fasta)
skip_if_not_installed("motifmatchr")
motif.matrix <- suppressWarnings(CreateMotifMatrix(
features = granges(atac_small),
pwm = pwm,
genome = genome
))
expect_equal(dim(motif.matrix), c(323, 2))
features <- suppressWarnings(c(
granges(atac_small),
GenomicRanges::GRanges(
seqnames = "fake_chr",
ranges = IRanges::IRanges(start = 1, end = 1000)
)
))
skip_if_not_installed("BSgenome.Hsapiens.UCSC.hg19")
motif.matrix <- suppressWarnings(CreateMotifMatrix(
features = features,
pwm = pwm,
genome = BSgenome.Hsapiens.UCSC.hg19::BSgenome.Hsapiens.UCSC.hg19
))
expect_equal(dim(motif.matrix), c(324, 2))
})

0 comments on commit 1eb526c

Please sign in to comment.