logo
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

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

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

Creates the genetic code of yeast mitochondrial

Creates the genetic code of invertebrate mitochondrial

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()
);

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

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]
);

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]));

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]));

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

Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.