Skip to contents

Convert DNA to 3-base codons

Usage

dna2codon(x, ...)

Arguments

x

character vector assumed to contain DNA or RNA nucleotides

...

additional arguments are ignored.

Value

character vector where each element contains three characters, e.g. all(nchar(dna2codon(x)) == 3).

Details

This function takes character string input, either as one large string or vector of strings such as those read from a FASTA file, and returns a vector of 3-base codons. The final codon must contain all three character values otherwise it is removed.

See also

Examples

dna <- c("atgggattatag");
dna2codon(dna);
#>     1     2     3     4 
#> "atg" "gga" "tta" "tag" 

# example adding one extra base, which does not make a full codon
dnaext1 <- c("atgggattataga");
dna2codon(dnaext1);
#>     1     2     3     4 
#> "atg" "gga" "tta" "tag"