A Rust implementation of Needleman-Wunsch & Smith-Waterman sequence alignment.
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.
Add the most recent version of seal
to your dependencies in your project's Cargo.toml
.
Then add …
rust
extern crate seal;
… to your crate's root file (e.g. lib.rs
, main.rs
).
Once that's done you're ready to play!
```rust extern crate seal;
use seal::pair::{SmithWaterman, NeedlemanWunsch, AlignmentSet, Alignment, MemoryBacking, Step};
fn main() { let strx = "The quick brown fox jumps over the lazy dog."; let stry = "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::new(sequence_x.len(),
sequence_y.len(),
strategy,
MemoryBacking::MemoryBacked,
|x, y| sequence_x[x] == sequence_y[y]);
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.
An AlignmentSet
contains all optimal alignments for a given pair of sequences.
rust
let alignment in set.local_alignment();
let alignment in global_alignment();
rust
for alignment in set.local_alignments() {
// …
}
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
See also the list of contributors who participated in this project.
This project is licensed under the MPL-2.0 – see the LICENSE.md file for details.