From 0a74f17977774ec2ac5da788344c11cac46c136b Mon Sep 17 00:00:00 2001 From: DominikRafacz Date: Sun, 29 Sep 2024 17:56:26 +0200 Subject: [PATCH 1/2] update date --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c8c7f99..aa64844 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: tidysq Type: Package Title: Tidy Processing and Analysis of Biological Sequences Version: 1.2.1 -Date: 2022-01-29 +Date: 2024-09-29 Authors@R: c(person("Dominik", "Rafacz", email = "dominikrafacz@gmail.com", comment = c(ORCID = "0000-0003-0925-1909"), From 10168a04886fa12de9231aea4e6a34c97138d76c Mon Sep 17 00:00:00 2001 From: DominikRafacz Date: Sun, 6 Oct 2024 19:55:00 +0200 Subject: [PATCH 2/2] add skips to packages used in tests and examples if not installed --- .Rbuildignore | 1 + NEWS.md | 1 + R/export_sq.R | 10 +++++----- R/find_motifs.R | 16 ++++++++-------- R/import_sq.R | 15 +++++++++------ R/write_fasta.R | 12 ++++++------ cran-comments.md | 1 + man/export_sq.Rd | 7 ++++--- man/import_sq.Rd | 12 ++++++++---- tests/testthat/setup-tests.R | 2 +- tests/testthat/test-casting.R | 24 +++++++++++++++--------- tests/testthat/test-export_sq.R | 2 ++ tests/testthat/test-find_motifs.R | 2 ++ tests/testthat/test-pkg-Biostrings.R | 2 ++ tests/testthat/test-pkg-ape.R | 2 ++ tests/testthat/test-pkg-bioseq.R | 2 ++ tests/testthat/test-pkg-seqinr.R | 2 ++ tests/testthat/test-random_sq.R | 1 + 18 files changed, 72 insertions(+), 42 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index d969e99..55d81f4 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -19,3 +19,4 @@ docs ^src/main\.cpp$ ^src/CMakeLists\.txt$ ^src/cmake-build-debug$ +^CRAN-SUBMISSION$ diff --git a/NEWS.md b/NEWS.md index 237b5cb..5108246 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ ## Fixed: * fixed incorrect codons * add explicit casting of alphabet during construction of sequence prototype (fixes issues with new implementation of `union()`) +* add skips for tests that use not available packages from "Suggests" # tidysq 1.2.0 ## New features: diff --git a/R/export_sq.R b/R/export_sq.R index a974c4a..8e39394 100644 --- a/R/export_sq.R +++ b/R/export_sq.R @@ -1,7 +1,7 @@ #' Export sq objects into other formats #' #' @templateVar name_null_ok TRUE -#' +#' #' @description Converts object of class \code{\link[=sq-class]{sq}} to a class #' from another package. Currently supported packages are \pkg{ape}, #' \pkg{bioseq}, \pkg{Bioconductor} and \pkg{seqinr}. For exact list of @@ -13,8 +13,8 @@ #' @template name #' @template three-dots #' -#' @return An object with the format specified in the parameter. To find -#' information about the detailed structure of this object, see documentation +#' @return An object with the format specified in the parameter. To find +#' information about the detailed structure of this object, see documentation #' of these objects. #' #' @details @@ -44,7 +44,7 @@ #' } #' } #' -#' @examples +#' @examplesIf all(c(require("Biostrings", quietly = TRUE), require("ape", quietly = TRUE), require("bioseq", quietly = TRUE), require("seqinr", quietly = TRUE))) #' # DNA and amino acid sequences can be exported to most packages #' sq_ami <- sq(c("MVVGL", "LAVPP"), alphabet = "ami_bsc") #' export_sq(sq_ami, "ape::AAbin") @@ -72,7 +72,7 @@ export_sq <- function(x, export_format, name = NULL, ...) { assert_string(export_format) assert_character(name, len = vec_size(x), null.ok = TRUE) - + UseMethod("export_sq") } diff --git a/R/find_motifs.R b/R/find_motifs.R index dda4d6e..3819e6b 100644 --- a/R/find_motifs.R +++ b/R/find_motifs.R @@ -1,9 +1,9 @@ #' Find given motifs #' #' @templateVar name_null_ok FALSE -#' +#' #' @description Finds all given motifs in sequences and returns their positions. -#' +#' #' @template x #' @template name #' @param motifs [\code{character}]\cr @@ -12,7 +12,7 @@ #' @template dot-name #' @template NA_letter #' @template three-dots -#' +#' #' @return A \code{\link[tibble]{tibble}} with following columns: #' \item{name}{name of the sequence in which a motif was found} #' \item{sought}{sought motif} @@ -20,12 +20,12 @@ #' contained ambiguous letters} #' \item{start}{position of first element of found motif} #' \item{end}{position of last element of found motif} -#' +#' #' @details #' This function allows search of a given motif or motifs in the \code{sq} #' object. It returns all motifs found with their start and end positions within #' a sequence. -#' +#' #' @template motif_details #' #' @examples @@ -53,7 +53,7 @@ #' #' # Finding multicharacter motifs: #' find_motifs(sq_atp, sq_names, c("nsA", "mYmY$")) -#' +#' #' # It can be a part of tidyverse pipeline: #' library(dplyr) #' fasta_file <- system.file(package = "tidysq", "examples/example_aa.fasta") @@ -80,7 +80,7 @@ find_motifs.sq <- function(x, name, motifs, ..., assert_character(motifs, any.missing = FALSE) assert_string(NA_letter, min.chars = 1) assert_alph_no_special_chars(alphabet(x)) - + ret <- CPP_find_motifs(x, name, motifs, NA_letter) as_tibble(ret) } @@ -95,6 +95,6 @@ find_motifs.data.frame <- function(x, motifs, ..., assert_string(.sq, min.chars = 1) assert_string(.name, min.chars = 1) assert_subset(c(.sq, .name), colnames(x)) - + find_motifs(x[[.sq]], x[[.name]], motifs, ..., NA_letter = NA_letter) } diff --git a/R/import_sq.R b/R/import_sq.R index cda4c3a..85e616e 100644 --- a/R/import_sq.R +++ b/R/import_sq.R @@ -1,20 +1,20 @@ #' Import sq objects from other objects -#' +#' #' @description Creates \code{\link[=sq-class]{sq}} object from object of class #' from another package. Currently supported packages are \pkg{ape}, #' \pkg{bioseq}, \pkg{Bioconductor} and \pkg{seqinr}. For exact list of #' supported classes and resulting types, see details. -#' +#' #' @param object [\code{any(1)}]\cr #' An object of one of supported classes. #' @template three-dots -#' +#' #' @return A \code{\link[tibble]{tibble}} with \code{sq} column of #' \code{\link[=sq-class]{sq}} type representing the same sequences as given #' object; the object has a type corresponding to the input type; if given #' sequences have names, output \code{\link[tibble]{tibble}} will also have #' another column \code{name} with those names -#' +#' #' @details #' Currently supported classes are as follows: #' \itemize{ @@ -59,22 +59,25 @@ #' #' Providing object of class other than specified will result in an error. #' -#' @examples +#' @examplesIf require("ape", quietly = TRUE) #' # ape example #' library(ape) #' ape_dna <- as.DNAbin(list(one = c("C", "T", "C", "A"), two = c("T", "G", "A", "G", "G"))) #' import_sq(ape_dna) #' +#' @examplesIf require("bioseq", quietly = TRUE) #' # bioseq example #' library(bioseq) #' bioseq_rna <- new_rna(c(one = "ANBRY", two = "YUTUGGN")) #' import_sq(bioseq_rna) #' +#' @examplesIf require("Biostrings", quietly = TRUE) #' # Biostrings example #' library(Biostrings) #' Biostrings_ami <- AAStringSet(c(one = "FEAPQLIWY", two = "EGITENAK")) #' import_sq(Biostrings_ami) #' +#' @examplesIf require("seqinr", quietly = TRUE) #' # seqinr example #' library(seqinr) #' seqinr_dna <- as.SeqFastadna(c("C", "T", "C", "A"), name = "one") @@ -246,6 +249,6 @@ import_sq.list <- function(object, separate = TRUE, ...) { bind_into_sqibble <- function(x, name = NULL) { if (is.null(name)) tibble(sq = x) - else + else tibble(name = name, sq = x) } diff --git a/R/write_fasta.R b/R/write_fasta.R index 05221f7..2eb1793 100644 --- a/R/write_fasta.R +++ b/R/write_fasta.R @@ -1,7 +1,7 @@ #' Save sq to fasta file #' #' @templateVar name_null_ok FALSE -#' +#' #' @description Writes \code{\link[=sq-class]{sq}} objects with their names to #' a fasta file. #' @@ -17,7 +17,7 @@ #' @template three-dots #' #' @return No value is returned. -#' +#' #' @details #' Whenever a name has more letters than \code{width} parameter, nothing #' happens, as only sequences are split to fit within designated space. @@ -30,7 +30,7 @@ #' c("bat", "cat", "rat", "elephant_swallowed_by_A_snake"), #' tempfile()) #' } -#' +#' #' # It can be a part of tidyverse pipeline: #' library(dplyr) #' fasta_file <- system.file(package = "tidysq", "examples/example_aa.fasta") @@ -58,7 +58,7 @@ write_fasta.sq <- function(x, name, file, assert_string(file) assert_count(width, positive = TRUE) assert_string(NA_letter, min.chars = 1) - + CPP_write_fasta(x, name, file, width, NA_letter) } @@ -73,6 +73,6 @@ write_fasta.data.frame <- function(x, file, assert_string(.sq, min.chars = 1) assert_string(.name, min.chars = 1) assert_subset(c(.sq, .name), colnames(x)) - + write_fasta(x[[.sq]], x[[.name]], file, width = width, NA_letter = NA_letter) -} \ No newline at end of file +} diff --git a/cran-comments.md b/cran-comments.md index 72f33d2..146674e 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -4,3 +4,4 @@ * This is a resubmission. * Fixed issues related to new implementations of set operations on R-devel +* Added skips to tests that require using packages from "Suggests" diff --git a/man/export_sq.Rd b/man/export_sq.Rd index 343cc2d..ca6df39 100644 --- a/man/export_sq.Rd +++ b/man/export_sq.Rd @@ -20,8 +20,8 @@ Vector of sequence names. Must be of the same length as \code{sq} object. \item{...}{further arguments to be passed from or to other methods.} } \value{ -An object with the format specified in the parameter. To find -information about the detailed structure of this object, see documentation +An object with the format specified in the parameter. To find +information about the detailed structure of this object, see documentation of these objects. } \description{ @@ -58,6 +58,7 @@ Currently supported formats are as follows (grouped by \code{sq} types): } } \examples{ +\dontshow{if (all(c(require("Biostrings", quietly = TRUE), require("ape", quietly = TRUE), require("bioseq", quietly = TRUE), require("seqinr", quietly = TRUE)))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # DNA and amino acid sequences can be exported to most packages sq_ami <- sq(c("MVVGL", "LAVPP"), alphabet = "ami_bsc") export_sq(sq_ami, "ape::AAbin") @@ -78,7 +79,7 @@ export_sq(sq_rna, "Biostrings::RNAStringSet") # Biostrings can export single sequences to simple strings as well export_sq(sq_dna[1], "Biostrings::DNAString") - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=sq-class]{sq class}} diff --git a/man/import_sq.Rd b/man/import_sq.Rd index 6bb2d27..3361ed8 100644 --- a/man/import_sq.Rd +++ b/man/import_sq.Rd @@ -70,26 +70,30 @@ Currently supported classes are as follows: Providing object of class other than specified will result in an error. } \examples{ +\dontshow{if (require("ape", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # ape example library(ape) ape_dna <- as.DNAbin(list(one = c("C", "T", "C", "A"), two = c("T", "G", "A", "G", "G"))) import_sq(ape_dna) - +\dontshow{\}) # examplesIf} +\dontshow{if (require("bioseq", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # bioseq example library(bioseq) bioseq_rna <- new_rna(c(one = "ANBRY", two = "YUTUGGN")) import_sq(bioseq_rna) - +\dontshow{\}) # examplesIf} +\dontshow{if (require("Biostrings", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Biostrings example library(Biostrings) Biostrings_ami <- AAStringSet(c(one = "FEAPQLIWY", two = "EGITENAK")) import_sq(Biostrings_ami) - +\dontshow{\}) # examplesIf} +\dontshow{if (require("seqinr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # seqinr example library(seqinr) seqinr_dna <- as.SeqFastadna(c("C", "T", "C", "A"), name = "one") import_sq(seqinr_dna) - +\dontshow{\}) # examplesIf} } \seealso{ \code{\link[=sq-class]{sq class}} diff --git a/tests/testthat/setup-tests.R b/tests/testthat/setup-tests.R index 821231b..b2b5dc7 100644 --- a/tests/testthat/setup-tests.R +++ b/tests/testthat/setup-tests.R @@ -3,7 +3,7 @@ test_sq_only <- function(.func, ..., .data.frame_ok = FALSE) { test_message <- if (.data.frame_ok) "the first argument must be of sq or data.frame class" else "the first argument must be of sq class" - + test_that(test_message, { expect_s3_class(rlang::catch_cnd(.func(1:7, ...)), "error_no_method") diff --git a/tests/testthat/test-casting.R b/tests/testthat/test-casting.R index a656b29..80e9a5c 100644 --- a/tests/testthat/test-casting.R +++ b/tests/testthat/test-casting.R @@ -44,14 +44,6 @@ str_with_na_1 <- c("!A!T!!TC!", "", "AT!C!G!!", "", "!!A!!T!") str_with_na_2 <- c("?A?T??TC?", "", "AT?C?G??", "", "??A??T?") str_with_na_3 <- c("ATTC", "", "ATCG", "", "AT") -# added because of Biostrings warning -suppressWarnings({ - biostr_dna_bsc <- Biostrings::DNAStringSet(str_dna_bsc) -}) - -seqinr_ami_bsc <- lapply(str_ami_bsc, function(x) - seqinr::as.SeqFastaAA(seqinr::s2c(x))) - # CASTING TO SQ ---- test_that("character vector is casted to sq with as.sq()", { expect_identical(as.sq(str_rna_bsc), @@ -62,11 +54,25 @@ test_that("character vector is casted to sq with as.sq()", { sq(str_atp)) }) -test_that("non-character objects are passed to import_sq()", { +test_that("Biostrings objects are passed to import_sq()", { + skip_if_not_installed("Biostrings") + # suppression because of Biostrings warning + suppressWarnings({ + biostr_dna_bsc <- Biostrings::DNAStringSet(str_dna_bsc) + }) expect_identical(as.sq(biostr_dna_bsc), import_sq(biostr_dna_bsc)) +}) + +test_that("seqinr objects are passed to import_sq()", { + skip_if_not_installed("seqinr") + seqinr_ami_bsc <- lapply(str_ami_bsc, function(x) + seqinr::as.SeqFastaAA(seqinr::s2c(x))) expect_identical(as.sq(seqinr_ami_bsc), import_sq(seqinr_ami_bsc)) +}) + +test_that("Non-importable objects in import_sq() throw an error", { expect_error(as.sq(function(x, y) x + y)) }) diff --git a/tests/testthat/test-export_sq.R b/tests/testthat/test-export_sq.R index 0cce7e7..6969192 100644 --- a/tests/testthat/test-export_sq.R +++ b/tests/testthat/test-export_sq.R @@ -1,3 +1,5 @@ +skip_if_not_installed("Biostrings") + # SETUP ---- sq_dna <- sq(c("TACTGGGCATG", "CAGGTCGGA", "TAGTAGTCCG", "", "ACGGT"), alphabet = "dna_bsc") diff --git a/tests/testthat/test-find_motifs.R b/tests/testthat/test-find_motifs.R index 46fd021..398b566 100644 --- a/tests/testthat/test-find_motifs.R +++ b/tests/testthat/test-find_motifs.R @@ -164,6 +164,7 @@ test_that("'found' column can handle both special characters and ambiguous lette # INDEX COLUMNS ---- test_that("'start' and 'end' columns have values between 1 and length(sequence)", { + skip_if_not_installed("purrr") sqibble_1 <- find_motifs(sq_dna_bsc, names_5, "TAG") sqibble_1[["found_length"]] <- get_sq_lengths(sqibble_1[["found"]]) purrr::pwalk(sqibble_1, function(names, sought, found, start, end, found_length) { @@ -206,6 +207,7 @@ test_that("'start' and 'end' columns have values between 1 and length(sequence)" }) test_that("index columns can be used to retrieve found subsequence from original sequence", { + skip_if_not_installed("purrr") purrr::pwalk(find_motifs(sq_dna_bsc, names_5, "TAG"), function(names, sought, found, start, end) { expect_identical( bite(sq_dna_bsc[which(names == names_5)], start:end)[[1]], diff --git a/tests/testthat/test-pkg-Biostrings.R b/tests/testthat/test-pkg-Biostrings.R index 284dcf9..6ecee78 100644 --- a/tests/testthat/test-pkg-Biostrings.R +++ b/tests/testthat/test-pkg-Biostrings.R @@ -1,3 +1,5 @@ +skip_if_not_installed("Biostrings") + # SETUP ---- str_dna <- c("TACTGGGCATG", "CAGGTCGGA", "TAGTAGTCCG", "", "ACGGT") str_1_dna <- "TCYYCAHGGCHA" diff --git a/tests/testthat/test-pkg-ape.R b/tests/testthat/test-pkg-ape.R index 2f51f25..ed2659f 100644 --- a/tests/testthat/test-pkg-ape.R +++ b/tests/testthat/test-pkg-ape.R @@ -1,3 +1,5 @@ +skip_if_not_installed("ape") + # SETUP ---- str_dna <- c("TACTGGGCATG", "CAGGTCGGA", "TAGTAGTCCG", "", "ACGGT") str_ami <- c("REGENERATED", "TECHNICAL", "FEAT") diff --git a/tests/testthat/test-pkg-bioseq.R b/tests/testthat/test-pkg-bioseq.R index 7035888..6790ae7 100644 --- a/tests/testthat/test-pkg-bioseq.R +++ b/tests/testthat/test-pkg-bioseq.R @@ -1,3 +1,5 @@ +skip_if_not_installed("bioseq") + # SETUP ---- str_dna <- c("TACTGGGCATG", "CAGGTCGGA", "TAGTAGTCCG", "", "ACGGT") str_rna <- c("", "KBS-UVW-AWWWG", "YGHHH-", "-CRASH", "MND-KUUBV-MY-") diff --git a/tests/testthat/test-pkg-seqinr.R b/tests/testthat/test-pkg-seqinr.R index 12ddce8..5188c01 100644 --- a/tests/testthat/test-pkg-seqinr.R +++ b/tests/testthat/test-pkg-seqinr.R @@ -1,3 +1,5 @@ +skip_if_not_installed("seqinr") + # SETUP ---- str_dna <- c("TACTGGGCATG", "CAGGTCGGA", "TAGTAGTCCG", "", "ACGGT") str_ami <- c("REGENERATED", "TECHNICAL", "FEAT") diff --git a/tests/testthat/test-random_sq.R b/tests/testthat/test-random_sq.R index e3f7df8..91a9cfd 100644 --- a/tests/testthat/test-random_sq.R +++ b/tests/testthat/test-random_sq.R @@ -25,6 +25,7 @@ test_that("random_sq() doesn't accept \"unt\" as type", { # LENGTH SAFETY ---- test_that("using sd argument of random_sq() doesn't generate negative-length sequences", { + skip_if_not_installed("mockr") # Using local mock to ensure that rnorm generates some negative values # Will have to change it if random_sq() changes length generating function # This might suggest that we should extract this as a separate function