diff --git a/README.Rmd b/README.Rmd index bd60f17..eead206 100644 --- a/README.Rmd +++ b/README.Rmd @@ -21,6 +21,7 @@ knitr::opts_chunk$set( ```{r coverage, echo=FALSE} +Sys.setenv(NOT_CRAN = "true") cov <- covr::package_coverage() pct <- covr::percent_coverage(cov) pct_label <- sprintf("%.1f%%", pct) diff --git a/README.md b/README.md index 4e87647..bca4fa8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![status](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![R build status](https://github.com/sbthandras/tailor/workflows/R-CMD-check/badge.svg)](https://github.com/sbthandras/tailor/actions) -[![Coverage](https://img.shields.io/badge/coverage-56.1%25-orange)](#test-coverage) +[![Coverage](https://img.shields.io/badge/coverage-92.9%25-brightgreen)](#test-coverage) [![DOI](https://img.shields.io/badge/DOI-10.64898%2F2026.02.20.706991-blue)](https://doi.org/10.64898/2026.02.20.706991) diff --git a/tests/testthat/_snaps/plot_position_scores/position-scores-cemean.svg b/tests/testthat/_snaps/plot_position_scores/position-scores-cemean.svg new file mode 100644 index 0000000..3f10958 --- /dev/null +++ b/tests/testthat/_snaps/plot_position_scores/position-scores-cemean.svg @@ -0,0 +1,995 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-6 +-3 +0 +3 +6 + + + + + + + + + +0 +250 +500 +750 +Amino acid position from N terminal +10 point moving average of substitution scores +(BLOSUM80) + +Domain + + + + +C-terminal +N-terminal +position-scores-cemean + + diff --git a/tests/testthat/_snaps/plot_position_scores/position-scores-cusum.svg b/tests/testthat/_snaps/plot_position_scores/position-scores-cusum.svg new file mode 100644 index 0000000..8655173 --- /dev/null +++ b/tests/testthat/_snaps/plot_position_scores/position-scores-cusum.svg @@ -0,0 +1,1013 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +250 +500 +750 + + + + + + + + +0 +250 +500 +750 +Amino acid position from N terminal +Cumulative sum of substitution scores +(BLOSUM80) + +Domain + + + + +C-terminal +N-terminal + +Method + + + + + + + + + + +cemean +cusum +ewma +window +xbarone +position-scores-cusum + + diff --git a/tests/testthat/_snaps/plot_position_scores/position-scores-indiv.svg b/tests/testthat/_snaps/plot_position_scores/position-scores-indiv.svg new file mode 100644 index 0000000..ab021aa --- /dev/null +++ b/tests/testthat/_snaps/plot_position_scores/position-scores-indiv.svg @@ -0,0 +1,1012 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-5 +0 +5 +10 + + + + + + + + +0 +250 +500 +750 +Amino acid position from N terminal +Substitution score +(BLOSUM80) + +Domain + + + + +C-terminal +N-terminal + +Method + + + + + + + + + + +cemean +cusum +ewma +window +xbarone +position-scores-indiv + + diff --git a/tests/testthat/test-adapter_matrix.R b/tests/testthat/test-adapter_matrix.R index cda64a4..7a5c524 100644 --- a/tests/testthat/test-adapter_matrix.R +++ b/tests/testthat/test-adapter_matrix.R @@ -11,6 +11,20 @@ test_that("adapter_matrix() works", { expect_equal(amat[index_x, index_y], 0.876) }) +test_that("adapter_matrix() work with multiple cores", { + skip_on_cran() + data(adapters) + amat <- adapters |> adapter_matrix(cores = 2) + + expect_true(inherits(amat, "adapter_matrix")) + expect_equal(dim(amat), c(20,20)) + expect_equal(unique(diag(amat)), 1) + + index_x <- which(rownames(amat) == "MN395291-1") + index_y <- which(colnames(amat) == "ON513429-1") + expect_equal(amat[index_x, index_y], 0.876) +}) + test_that("adapter_matrix() fails when input is not an adapter df", { data(rbps) diff --git a/tests/testthat/test-cluster_adapters.R b/tests/testthat/test-cluster_adapters.R index 9891256..6b3c5de 100644 --- a/tests/testthat/test-cluster_adapters.R +++ b/tests/testthat/test-cluster_adapters.R @@ -14,6 +14,18 @@ test_that("cluster_adapters() works", { expect_equal(clusters2 |> dplyr::pull(cluster) |> unique() |> length(), 2) }) +test_that("cluster_adapters() works with multiple cores", { + skip_on_cran() + data(rbps) + data(adapters) + amat <- adapter_matrix(adapters) + + clusters1 <- cluster_adapters(amat, k_min = 1, cores = 2) + expect_true(inherits(clusters1, "data.frame")) + expect_equal(dim(clusters1), c(20,2)) + expect_equal(clusters1 |> dplyr::pull(cluster) |> unique() |> length(), 2) +}) + test_that("cluster_adapters() fails when input is not an adapter matrix", { data(rbps) expect_error(cluster_adapters(rbps, k_min = 2, k_max = 5)) diff --git a/tests/testthat/test-completeness.R b/tests/testthat/test-completeness.R index 6b4d147..8a4423a 100644 --- a/tests/testthat/test-completeness.R +++ b/tests/testthat/test-completeness.R @@ -8,4 +8,11 @@ test_that("completeness() works", { out <- completeness(mat = amat, index = index) expect_equal(out, 1) + + expect_error(completeness(mat = amat, index = vector())) + msg <- capture_error(completeness(mat = amat, index = vector())) + expect_equal( + msg$message, + "cluster must contain at least one element. Please provide indices." + ) }) diff --git a/tests/testthat/test-find_all_adapters.R b/tests/testthat/test-find_all_adapters.R index c8d4f25..007caa7 100644 --- a/tests/testthat/test-find_all_adapters.R +++ b/tests/testthat/test-find_all_adapters.R @@ -6,3 +6,13 @@ test_that("find_all_adapters() works", { expect_equal(nrow(adapters), 3) expect_equal(adapters$pident, c(0.901, 0.940, 0.914)) }) + +test_that("find_all_adapters() work with multiple cores", { + skip_on_cran() + data(rbps) + adapters <- find_all_adapters(rbps$Core_ORF[1:3], data = rbps, cores = 2) + + expect_true(inherits(adapters, "adapter")) + expect_equal(nrow(adapters), 3) + expect_equal(adapters$pident, c(0.901, 0.940, 0.914)) +}) diff --git a/tests/testthat/test-find_breakpoints.R b/tests/testthat/test-find_breakpoints.R index 3bf1034..55ff435 100755 --- a/tests/testthat/test-find_breakpoints.R +++ b/tests/testthat/test-find_breakpoints.R @@ -7,12 +7,9 @@ test_that("find_breakpoints() works", { window <- find_breakpoints(ps, method = "window", window = 5) expect_true(inherits(cemean, "breakpoints")) - expect_equal(dim(cemean), c(5, 6)) - expect_equal(cemean$pident[1], 0.947) - expect_equal(dim(ewma), c(6, 6)) - expect_equal(ewma$pident[1], 0.936) - expect_equal(dim(cusum), c(4, 6)) - expect_equal(cusum$pident[1], 0.936) - expect_equal(dim(window), c(69, 6)) - expect_equal(window$pident[1], 0.886) + + expect_equal(cemean$end[1], 152) + expect_equal(ewma$end[1], 157) + expect_equal(cusum$end[1], 157) + expect_true(window$end[1] >= 175) }) diff --git a/tests/testthat/test-plot_adapter_matrix.R b/tests/testthat/test-plot_adapter_matrix.R index 77b5c8f..6bdfc07 100755 --- a/tests/testthat/test-plot_adapter_matrix.R +++ b/tests/testthat/test-plot_adapter_matrix.R @@ -10,3 +10,15 @@ test_that("plot() works with adapter matrices", { vdiffr::expect_doppelganger("amat-without-clusters", g1) vdiffr::expect_doppelganger("amat-with-clusters", g2) }) + +test_that("plot() works with adapter matrices - covr hack", { + data(rbps) + data(adapters) + amat <- adapter_matrix(adapters) + g1 <- plot(amat) + clusters <- cluster_adapters(amat, k_min = 2, k_max = 2) + g2 <- plot(amat, clusters = clusters) + + expect_true(inherits(g1, "ggplot")) + expect_true(inherits(g2, "ggplot")) +}) diff --git a/tests/testthat/test-plot_position_scores.R b/tests/testthat/test-plot_position_scores.R index f7e36d4..3dc7194 100755 --- a/tests/testthat/test-plot_position_scores.R +++ b/tests/testthat/test-plot_position_scores.R @@ -2,7 +2,27 @@ test_that("plot() works with position scores", { skip_on_ci() data(rbps) ps <- position_scores("MN395291-1", "ON513429-1", data = rbps) - g <- plot(ps) + g1 <- plot(ps) + g2 <- plot(ps, method = "cemean", highlight = "cemean") + g3 <- plot(ps, type = "indiv") + g4 <- plot(ps, type = "cusum") - vdiffr::expect_doppelganger("position-scores", g) + vdiffr::expect_doppelganger("position-scores", g1) + vdiffr::expect_doppelganger("position-scores-cemean", g2) + vdiffr::expect_doppelganger("position-scores-indiv", g3) + vdiffr::expect_doppelganger("position-scores-cusum", g4) +}) + +test_that("plot() works with position scores - covr hack", { + data(rbps) + ps <- position_scores("MN395291-1", "ON513429-1", data = rbps) + g1 <- plot(ps) + g2 <- plot(ps, method = "cemean", highlight = "cemean") + g3 <- plot(ps, type = "indiv") + g4 <- plot(ps, type = "cusum") + + expect_true(inherits(g1, "ggplot")) + expect_true(inherits(g2, "ggplot")) + expect_true(inherits(g3, "ggplot")) + expect_true(inherits(g4, "ggplot")) }) diff --git a/tests/testthat/test-schoco.R b/tests/testthat/test-schoco.R index e69de29..b38b589 100644 --- a/tests/testthat/test-schoco.R +++ b/tests/testthat/test-schoco.R @@ -0,0 +1,14 @@ +test_that("schoco works()", { + data(rbps) + data(adapters) + amat <- adapter_matrix(adapters, ids = rbps$Core_ORF) + out <- schoco(amat, k = 2) + expect_equal(dim(out), c(2, 6)) + + expect_error(schoco(adapters, 2)) + msg <- capture_error(schoco(adapters, 2)) + expect_equal(msg$message, paste0( + "mat must be a matrix of class 'adapter_matrix'. ", + "Use adapter_matrix() to create a compatible matrix." + )) +})