[][src]Function protein_translate::translate

pub fn translate(seq: &[u8]) -> String

Translate DNA or RNA sequence into a peptide.

Examples

use protein_translate::translate;

fn dna_example() {
     
    let dna = b"GCTAGTCGTATCGTAGCTAGTC";
    let peptide = translate(dna);
    assert_eq!(&peptide, "ASRIVAS");

}

fn rna_example() {

    let rna = b"GCUAGUCGUAUCGUAGCUAGUC";
    let peptide = translate(rna);
    assert_eq!(&peptide, "ASRIVAS");
}

fn shift_reading_frame() {

    // To shift the reading frame, pass in a slice
    // skipping the first 1-2 nucleotides.

    let dna = b"GCTAGTCGTATCGTAGCTAGTC";
    let peptide_frame2 = translate(&dna[1..]);
    assert_eq!(&peptide_frame2, "LVVS*LV");

    let peptide_frame3 = translate(&dna[2..]);
    assert_eq!(&peptide_frame3, "*SYRS*");
    
}