protein-translate

Build Status Cargo Documentation

Translate nucleotide sequence (dna or rna) to protein.

Usage

Add this to your Cargo.toml:

toml [dependencies] protein-translate = "0.1.2"

Example

```rust use protein_translate::translate;

fn main() { let dna = "GTGAGTCGTTGAGTCTGATTGCGTATC"; let protein = translate(dna); assert_eq!("VSRVLRI", &protein);

// To shift reading frame
let protein_frame2 = translate(&dna[1..]);
assert_eq!("*VVESDCV", &protein_frame2);

} ```

Benchmarks

The current algorithm is inspired by seqan's implementation which uses array indexing. Here is how it performs vs other methods.

| Method | 10 bp* | 100 bp | 1,000 bp | 10,000 bp | 100,000 bp | | ------ | ---- | ----- | ------- | -------- | --------- | | proteintranslate | 87 ns | 0.22 μs | 1.74 μs | 15 μs | 157 μs | | fnv hashmap | 251 ns | 1.04 μs | 3.41 μs | 35 μs | 361 us | std hashmap | 159 ns | 1.02 μs | 9.69 μs | 100 μs | 966 μs | | phfmap | 190 ns | 1.13 μs | 10.56 μs | 105 μs | 1021 μs | | match statement | 270 ns | 1.74 μs | 18.4 μs | 173 μs | 1907 μs |

*bp = "base pairs"

To benchmark yourself (have to use nightly because of phf_map macro).

cargo +nightly bench

If you have a better implementation feel free to submit a merge request!

Todo

Tests

To test

cargo test

To can also generate new test data (requires python3 and biopython).

```bash

Generate 500 random sequences and their peptides

python3 tests/generatetestdata.py 500 ```