Crates.io | libwfa |
lib.rs | libwfa |
version | 0.1.2 |
source | src |
created_at | 2020-10-28 00:08:24.836225 |
updated_at | 2020-10-30 03:41:17.17991 |
description | Bindings to the C implementation of the WFA alignment algorithm |
homepage | |
repository | https://github.com/chfi/rs-wfa |
max_upload_size | |
id | 306172 |
size | 353,648 |
Rust bindings for the wavefront algorithm for pairwise sequence alignment.
This crate will handle compiling the C library, and statically link it.
Just add libwfa
to your Cargo dependencies:
[dependencies]
libwfa = "0.1"
As a binding, llvm and libclang are required on Unix systems. These can be installed by package managers, for example on Ubuntu with:
sudo apt install llvm
sudo apt install libclang-dev
At this stage, usage maps closely to the C library.
This is equivalent to the basic example from the WFA readme:
use libwfa::{affine_wavefront::*, bindings::*, mm_allocator::*, penalties::*};
fn main() {
let alloc = MMAllocator::new(BUFFER_SIZE_8M as u64);
let pattern = String::from("TCTTTACTCGCGCGTTGGAGAAATACAATAGT");
let text = String::from("TCTATACTGCGCGTTTGGAGAAATAAAATAGT");
let mut penalties = AffinePenalties {
match_: 0,
mismatch: 4,
gap_opening: 6,
gap_extension: 2,
};
let pat_len = pattern.as_bytes().len();
let text_len = text.as_bytes().len();
let mut wavefronts = AffineWavefronts::new_complete(
pat_len,
text_len,
&mut penalties,
&alloc,
);
wavefronts
.align(pattern.as_bytes(), text.as_bytes())
.unwrap();
let score = wavefronts.edit_cigar_score(&mut penalties);
println!("score: {}", score);
wavefronts.print_cigar(pattern.as_bytes(), text.as_bytes());
// The cigar can also be extracted as a byte vector
let cigar = wavefronts.cigar_bytes_raw();
let cg_str = std::str::from_utf8(&cigar).unwrap();
println!("cigar: {}", cg_str);
// Or as a prettier byte vector
let cigar = wavefronts.cigar_bytes();
let cg_str = std::str::from_utf8(&cigar).unwrap();
println!("cigar: {}", cg_str);
}
See the tests for more examples.
Make sure to clone with the WFA submodule:
git clone --recursive https://github.com/chfi/wfa-rs
cd wfa-rs
cargo build