Joins sequences from a vector into a single sequence. Sequence type remains unchanged.

collapse(x, ...)

# S3 method for sq
collapse(x, ..., NA_letter = getOption("tidysq_NA_letter"))

Arguments

x

[sq]
An object this function is applied to.

...

further arguments to be passed from or to other methods.

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

sq object of the same type as input but with exactly one sequence.

Details

collapse() joins sequences from supplied 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.

See also

Functions that affect order of elements: bite(), paste(), reverse()

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)
#> extended amino acid sequences list:
#> [1] MIAANYTWILTIAALGNIIYRAIENYERTGHLIMAYXXXIALN                             <43>
collapse(sq_dna)
#> extended DNA sequences list:
#> [1] ATGCAGGAGACCGAACGAN                                                     <19>
collapse(sq_unt)
#> unt (unspecified type) sequences list:
#> [1] ATGCAGGA?TGACGAGCTTATIAALGNIIYRAIE                                      <34>

# Empty sq objects are collapsed as well (into empty string - ""):
sq_empty <- sq(character(), alphabet = "rna_bsc")
collapse(sq_empty)
#> basic RNA sequences list:
#> [1] <NULL>                                                                   <0>