sqapply {tidysq} | R Documentation |
Apply function to each sequence
Description
Applies given function to each sequence. Sequences are passed to function as character vectors
(or numeric, if type of sq
is enc) or single character strings, depending on
parameter.
Usage
sqapply(
x,
fun,
...,
single_string = FALSE,
NA_letter = getOption("tidysq_NA_letter")
)
Arguments
x |
[ |
fun |
[ |
... |
further arguments to be passed from or to other methods. |
single_string |
[ |
NA_letter |
[ |
Value
A list of values returned by function for each sequence in corresponding order.
See Also
Examples
# Creating objects to work on:
sq_dna <- sq(c("ATGCAGGA", "GACCGNBAACGAN", "TGACGAGCTTA"),
alphabet = "dna_bsc")
sq_ami <- sq(c("MIAANYTWIL","TIAALGNIIYRAIE", "NYERTGHLI", "MAYXXXIALN"),
alphabet = "ami_ext")
sq_unt <- sq(c("ATGCAGGA?", "TGACGAGCTTA", "", "TIAALGNIIYRAIE"))
# Counting how may "A" elements are present in sequences:
sqapply(sq_dna, function(sequence) sum(sequence == "A"))
sqapply(sq_ami, function(sequence) sum(sequence == "A"))
sqapply(sq_unt, function(sequence) sum(sequence == "A"))