#sequence-alignment #nlp #dna #needleman-wunsch #smith-waterman

seal

Implementation of Needleman-Wunsch & Smith-Waterman sequence alignment

4 releases

0.1.5 May 12, 2022
0.1.4 Apr 5, 2022
0.1.3 Mar 6, 2022
0.1.2 Dec 12, 2021
0.1.0 May 3, 2017

#153 in Biology

Download history 142/week @ 2024-06-13 83/week @ 2024-06-20 104/week @ 2024-06-27 178/week @ 2024-07-04 173/week @ 2024-07-11 85/week @ 2024-07-18 92/week @ 2024-07-25 60/week @ 2024-08-01 78/week @ 2024-08-08 49/week @ 2024-08-15 89/week @ 2024-08-22 96/week @ 2024-08-29 51/week @ 2024-09-05 65/week @ 2024-09-12 93/week @ 2024-09-19 81/week @ 2024-09-26

305 downloads per month
Used in 2 crates (via stam-tools)

MPL-2.0 license

29KB
761 lines

seal

Downloads Version License

Synopsis

A Rust implementation of Needleman-Wunsch & Smith-Waterman sequence alignment.

Motivation

The aim of this crate is to provide a memory- and time-efficient implementation of Needleman-Wunsch as well as Smith-Waterman sequence alignment using a unified API.

Getting Started

Add the most recent version of seal to your dependencies in your project's Cargo.toml.

Then add …

extern crate seal;

… to your crate's root file (e.g. lib.rs, main.rs).

Once that's done you're ready to play!

Example

extern crate seal;

use seal::pair::{
    Alignment, AlignmentSet, InMemoryAlignmentMatrix, NeedlemanWunsch, SmithWaterman, Step,
};

fn main() {
    let str_x = "The quick brown fox jumps over the lazy dog.";
    let str_y = "The brown dog jumps over the very lazy snail.";

    let strategy = NeedlemanWunsch::new(1, -1, -1, -1);
    // Alternatively:
    // let strategy = SmithWaterman::new(2, -1, -1, -1);

    let sequence_x: Vec<char> = str_x.chars().collect();
    let sequence_y: Vec<char> = str_y.chars().collect();
    let set: AlignmentSet<InMemoryAlignmentMatrix> =
        AlignmentSet::new(sequence_x.len(), sequence_y.len(), strategy, |x, y| {
            sequence_x[x] == sequence_y[y]
        })
        .unwrap();

    let print_alignment = |alignment: Alignment| {
        for step in alignment.steps() {
            match step {
                Step::Align { x, y } => {
                    if sequence_x[x] == sequence_y[y] {
                        print!("=")
                    } else {
                        print!("!")
                    }
                }
                Step::Delete { .. } => print!("-"),
                Step::Insert { .. } => print!("+"),
            }
        }
        println!("\n");
    };

    println!("Local alignment:");
    let local_alignment = set.local_alignment();
    print_alignment(local_alignment);

    println!("Global alignment:");
    let global_alignment = set.global_alignment();
    print_alignment(global_alignment);

    // Local alignment:
    // ====------======!=!================+++++=====
    //
    // Global alignment:
    // ====------======!=!================+++++=====!!!++=
}

See the examples directory for more in-depth examples.

API Reference

An AlignmentSet contains all optimal alignments for a given pair of sequences.

Retrieving a single locally/globally optimal alignment

let alignment in alignment_set.local_alignment();
let alignment in alignment_set.global_alignment();

Enumerate all locally/globally optimal alignments

for alignment in alignment_set.local_alignments() {
    //
}
for alignment in alignment_set.global_alignments() {
    //
}

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MPL-2.0 – see the LICENSE.md file for details.

Dependencies

~2–11MB
~121K SLoC