-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,230 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#' Collapse multiple sequences into one | ||
#' | ||
#' @description Joins sequences from a vector into a single sequence. Sequence | ||
#' type remains unchanged. | ||
#' | ||
#' @template x | ||
#' @template NA_letter | ||
#' @template three-dots | ||
#' | ||
#' @return \code{\link[=sq-class]{sq}} object of the same type as input but with | ||
#' exactly one sequence. | ||
#' | ||
#' @details | ||
#' \code{collapse()} joins sequences from supplied \code{sq} object in the same | ||
#' order as they appear in said vector. That is, if there are three sequences | ||
#' AGGCT, ATCCGT and GAACGT, then resulting sequence will be AGGCTATCCGTGAACGT. | ||
#' This operation does not alter the type of the input object nor its alphabet. | ||
#' | ||
#' @examples | ||
#' # Creating objects to work on: | ||
#' sq_ami <- sq(c("MIAANYTWIL","TIAALGNIIYRAIE", "NYERTGHLI", "MAYXXXIALN"), | ||
#' alphabet = "ami_ext") | ||
#' sq_dna <- sq(c("ATGCAGGA", "GACCGAACGAN", ""), alphabet = "dna_ext") | ||
#' sq_unt <- sq(c("ATGCAGGA?", "TGACGAGCTTA", "", "TIAALGNIIYRAIE")) | ||
#' | ||
#' # Collapsing sequences: | ||
#' collapse(sq_ami) | ||
#' collapse(sq_dna) | ||
#' collapse(sq_unt) | ||
#' | ||
#' # Empty sq objects are collapsed as well (into empty string - ""): | ||
#' sq_empty <- sq(character(), alphabet = "rna_bsc") | ||
#' collapse(sq_empty) | ||
#' | ||
#' @family order_functions | ||
#' @export | ||
collapse <- function(x, ...) | ||
UseMethod("collapse") | ||
|
||
#' @export | ||
collapse.default <- function(x, ...) | ||
stop("method 'collapse' isn't implemented for this type of object", call. = FALSE) | ||
|
||
#' @rdname collapse | ||
#' @export | ||
collapse.sq <- function(x, ..., | ||
NA_letter = getOption("tidysq_NA_letter")) { | ||
assert_string(NA_letter, min.chars = 1) | ||
|
||
CPP_collapse(x, NA_letter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' @export | ||
paste <- function(...) | ||
UseMethod("paste") | ||
|
||
#' @export | ||
paste.default <- function(...) { | ||
base::paste(...) | ||
} | ||
|
||
#' Paste sequences in string-like fashion | ||
#' | ||
#' @description Joins multiple vectors of sequences into one vector. | ||
#' | ||
#' @param ... [\code{sq}]\cr | ||
#' Sequences to paste together. | ||
#' @template NA_letter | ||
#' | ||
#' @return \code{\link[=sq-class]{sq}} object of common type of input objects. | ||
#' Common type is determined in the same process as for | ||
#' \code{\link[=sq-concatenate]{c.sq}()}. | ||
#' | ||
#' @details | ||
#' \code{paste()} joins sequences in the same way as it does with strings. | ||
#' All \code{sq} objects must have the same length, that is, contain the same | ||
#' number of sequences. An exception is made for scalar (length 1) \code{sq} | ||
#' objects, which are replicated instead. | ||
#' | ||
#' @examples | ||
#' # Creating objects to work on: | ||
#' sq_dna_1 <- sq(c("TTCAGGGCTAG", "CGATTGC", "CAGTTTA"), | ||
#' alphabet = "dna_bsc") | ||
#' sq_dna_2 <- sq(c("ATCTTGAAG", "CATATGCGCTA", "ACGTGTCGA"), | ||
#' alphabet = "dna_bsc") | ||
#' sq_unt_1 <- sq(c("ATGCAGGA?", "TGACGAGCTTA", "", "TIAALGNIIYRAIE")) | ||
#' sq_unt_2 <- sq(c("OVNU!!OK!!J", "GOK!MI!N!BB!", "DPOFIN!!", "??!?")) | ||
#' | ||
#' # Pasting sequences: | ||
#' collapse(sq_dna_1, sq_dna_2) | ||
#' collapse(sq_unt_1, sq_unt_2) | ||
#' collapse(sq_dna_2, sq_unt_2, sq_dna_1) | ||
#' | ||
#' @family order_functions | ||
#' @name paste | ||
#' @export | ||
paste.sq <- function(..., | ||
NA_letter = getOption("tidysq_NA_letter")) { | ||
# Throws error when there is no common size | ||
vec_size_common(...) | ||
assert_string(NA_letter, min.chars = 1) | ||
|
||
CPP_paste(vec_cast_common(...), NA_letter) | ||
} |
Oops, something went wrong.