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

[sq]
An object this function is applied to.

fun

[function(1)]
A function to apply to each sequence in sq object; it should take a character vector, numeric vector or single character string as an input.

...

further arguments to be passed from or to other methods.

single_string

[logical(1)]
A value indicating in which form sequences should be passed to the function fun; if FALSE (default), they will be treated as character vectors, if TRUE, they will be pasted into a single string.

NA_letter

[character(1)]
A string that is used to interpret and display NA value in the context of sq class. Default value equals to "!".

Value

A list of values returned by function for each sequence in corresponding order.

See Also

sq lapply

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"))


[Package tidysq version 1.1.3 Index]