protein-translate
Translate nucleotide sequence (dna or rna) to protein.
Add this to your Cargo.toml
:
toml
[dependencies]
protein-translate = { git = "https://github.com/dweb0/protein-translate" }
Will add this to crates.io soon.
```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);
} ```
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 | | lazystatic | 159 ns | 1.02 μs | 9.69 μs | 100 μs | 966 μs | | phf_map | 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 |
You 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!
To test
cargo test
To can also generate new test data (requires python3 and biopython).
```bash
python3 tests/generatetestdata.py 500 ```