Learn R Programming

eDNAfuns (version 0.1.0)

count_stop_codons: Count stop codons or return translated sequence

Description

Given a DNA sequence (either a `DNAString` object or a character string), this function translates it using a specified genetic code and counts the number of stop codons (`*`) in the resulting amino acid sequence. Alternatively, the translated sequence itself can be returned.

Usage

count_stop_codons(
  sequence = NULL,
  format = "DNAString",
  codon = 1,
  dictionary = 5,
  return = "count"
)

Value

If `return = "count"`, an integer giving the number of stop codons. Otherwise, a character string with the translated amino acid sequence.

Arguments

sequence

A DNA sequence, either as a [Biostrings::DNAString] object or as a character string.

format

Input format, either `"DNAString"` (default) or `"character"`. If `"character"`, the sequence must consist of `A`, `C`, `G`, `T` only.

codon

Integer giving the starting codon position (usually 1, 2, or 3).

dictionary

Integer specifying which translation code to use. See [Biostrings::GENETIC_CODE_TABLE] for all options. Common examples:

idname
1Standard
2Vertebrate Mitochondrial
3Yeast Mitochondrial
4Mold/Protozoan/Coelenterate/Mycoplasma/Spiroplasma Mitochondrial
5Invertebrate Mitochondrial
6Ciliate/Dasycladacean/Hexamita Nuclear
9Echinoderm/Flatworm Mitochondrial
10Euplotid Nuclear
11Bacterial, Archaeal, and Plant Plastid
12Alternative Yeast Nuclear
13Ascidian Mitochondrial
14Alternative Flatworm Mitochondrial
15Blepharisma Macronuclear
16Chlorophycean Mitochondrial
21Trematode Mitochondrial
22Scenedesmus obliquus Mitochondrial
23Thraustochytrium Mitochondrial
24Pterobranchia Mitochondrial
25Candidate Division SR1 and Gracilibacteria
26Pachysolen tannophilus Nuclear

return

Either `"count"` (default) to return the number of stop codons, or any other value to return the translated amino acid sequence.

Author

Ramon Gallego, 2021

Details

The function uses [Biostrings::translate()] with the specified starting position and genetic code. Translation warnings are suppressed.

Examples

Run this code
if (requireNamespace("Biostrings", quietly = TRUE)) {
  library(Biostrings)
  seq <- DNAString("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
  count_stop_codons(seq, codon = 1, dictionary = 1)
  count_stop_codons(seq, codon = 1, dictionary = 1, return = "translation")
}

Run the code above in your browser using DataLab