Struct atglib::models::GeneticCode
source · [−]pub struct GeneticCode { /* private fields */ }Expand description
The genetic code is basically a lookup table from DNA codons to AminoAcids
Note
The genetic code does not support alternative start codons. ATGlib considers only ATG as start codon.
Examples
use atglib::models::{AminoAcid, GeneticCode, Nucleotide};
let code = GeneticCode::default();
assert_eq!(
code.translate(&[Nucleotide::A, Nucleotide::T, Nucleotide::G])
.unwrap(),
AminoAcid::M
);Implementations
sourceimpl GeneticCode
impl GeneticCode
sourcepub fn new(aa_table: &str) -> Result<GeneticCode, AtgError>
pub fn new(aa_table: &str) -> Result<GeneticCode, AtgError>
Creates a new, custom genetic code
The aa_table must be the amino acid translation for each possible codon, in the same order as the NCBI genetic code tables
The genetic code translation is provided as an array with 64 elements (one for each codon)
Examples
use atglib::models::{AminoAcid, GeneticCode, Nucleotide};
// use the genetic code table for `Yeast Mitochondrial`
let code = GeneticCode::new("FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG").unwrap();
assert_eq!(
code.translate(&[Nucleotide::T, Nucleotide::G, Nucleotide::A])
.unwrap(),
AminoAcid::W
);sourcepub fn vertebrate_mitochondrial() -> GeneticCode
pub fn vertebrate_mitochondrial() -> GeneticCode
Creates the genetic code of vertrebrate mitochondrial
Examples
use atglib::models::{AminoAcid, GeneticCode, Nucleotide};
let code = GeneticCode::vertebrate_mitochondrial();
assert_eq!(
code.translate(&[Nucleotide::A, Nucleotide::G, Nucleotide::A])
.unwrap(),
AminoAcid::Ter
);sourcepub fn yeast_mitochondrial() -> GeneticCode
pub fn yeast_mitochondrial() -> GeneticCode
Creates the genetic code of yeast mitochondrial
sourcepub fn invertebrate_mitochondrial() -> GeneticCode
pub fn invertebrate_mitochondrial() -> GeneticCode
Creates the genetic code of invertebrate mitochondrial
sourcepub fn guess(code: &str) -> Result<GeneticCode, AtgError>
pub fn guess(code: &str) -> Result<GeneticCode, AtgError>
Tries to create a genetic code from either a known code or from the provided lookup
This method can be used as a helper function for user-facing applications where users
can provide either the name of the code to use (e.g. vertebrate_mitochondria) or provide the
actual lookup table (e.g. FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG)
The names are based on the name field from the NCBI specs
but all lowercase characters. For example "Mold Mitochondrial; Protozoan Mitochondrial; Coelenterate Mitochondrial; Mycoplasma; Spiroplasma"
...
{
name "Mold Mitochondrial; Protozoan Mitochondrial; Coelenterate Mitochondrial; Mycoplasma; Spiroplasma" ,
name "SGC3" ,
id 4 ,
ncbieaa "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
sncbieaa "--MM------**-------M------------MMMM---------------M------------"
-- Base1 TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
-- Base2 TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
-- Base3 TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
},
...can be called as GeneticCode::guess("mold mitochondrial; protozoan mitochondrial; coelenterate mitochondrial; mycoplasma; spiroplasma")
or GeneticCode::guess("sgc3")
Examples
use atglib::models::GeneticCode;
assert_eq!(
GeneticCode::vertebrate_mitochondrial(),
GeneticCode::guess("vertebrate mitochondrial").unwrap()
);
assert_eq!(
GeneticCode::vertebrate_mitochondrial(),
GeneticCode::guess("FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG").unwrap()
);sourcepub fn translate(&self, codon: &[Nucleotide; 3]) -> Result<AminoAcid, AtgError>
pub fn translate(&self, codon: &[Nucleotide; 3]) -> Result<AminoAcid, AtgError>
Translates a provided codon into an AminoAcid
If the codon contains an N nucleotide, the method will return AtgError
Examples
use atglib::models::{AminoAcid, GeneticCode, Nucleotide};
let code = GeneticCode::default();
let aa = code.translate(&[Nucleotide::A, Nucleotide::T, Nucleotide::G]).unwrap();
assert_eq!(aa, AminoAcid::M);sourcepub fn reverse_lookup(&self, aa: &AminoAcid) -> Vec<[Nucleotide; 3]>
pub fn reverse_lookup(&self, aa: &AminoAcid) -> Vec<[Nucleotide; 3]>
Returns a vector of all codons that code for the provided AminoAcid
Examples
use atglib::models::{AminoAcid, GeneticCode, Nucleotide};
let code = GeneticCode::default();
let codons = code.reverse_lookup(&AminoAcid::M);
assert_eq!(
codons[0],
[Nucleotide::A, Nucleotide::T, Nucleotide::G]
);sourcepub fn stop_codons(&self) -> Vec<[Nucleotide; 3]>
pub fn stop_codons(&self) -> Vec<[Nucleotide; 3]>
Returns all possible Stop codons
Examples
use atglib::models::{GeneticCode, Nucleotide};
let code = GeneticCode::default();
let codons = code.stop_codons();
assert!(codons.contains(&[Nucleotide::T, Nucleotide::A, Nucleotide::A]));sourcepub fn is_stop_codon(&self, codon: &[Nucleotide]) -> bool
pub fn is_stop_codon(&self, codon: &[Nucleotide]) -> bool
Returns true if the provided codon is a stop codon
This method can only handle codons with exaccly 3 nucleotides. All other input will return false
Examples
use atglib::models::{GeneticCode, Nucleotide};
let code = GeneticCode::default();
assert!(code.is_stop_codon(&[Nucleotide::T, Nucleotide::A, Nucleotide::A]));sourcepub fn is_start_codon(codon: &[Nucleotide]) -> bool
pub fn is_start_codon(codon: &[Nucleotide]) -> bool
Returns true if the codon is a start codon
This method considers only the canonical ATG start codon and does
not include non-standard start codons
Examples
use atglib::models::{GeneticCode, Nucleotide};
assert!(GeneticCode::is_start_codon(&[Nucleotide::A, Nucleotide::T, Nucleotide::G]));Trait Implementations
sourceimpl Debug for GeneticCode
impl Debug for GeneticCode
sourceimpl Default for GeneticCode
impl Default for GeneticCode
sourcefn default() -> GeneticCode
fn default() -> GeneticCode
Crates the standard genetic code
