libwfa

Crates.iolibwfa
lib.rslibwfa
version0.1.2
sourcesrc
created_at2020-10-28 00:08:24.836225
updated_at2020-10-30 03:41:17.17991
descriptionBindings to the C implementation of the WFA alignment algorithm
homepage
repositoryhttps://github.com/chfi/rs-wfa
max_upload_size
id306172
size353,648
Christian Fischer (chfi)

documentation

README

libwfa

Rust bindings for the wavefront algorithm for pairwise sequence alignment.

Usage

This crate will handle compiling the C library, and statically link it.

Just add libwfa to your Cargo dependencies:

[dependencies]
libwfa = "0.1"

Dependencies

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

Example

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.

Build from source

Make sure to clone with the WFA submodule:

git clone --recursive https://github.com/chfi/wfa-rs
cd wfa-rs
cargo build
Commit count: 36

cargo fmt