Skip to content

Commit bc102fc

Browse files
authored
Merge pull request #15 from rust-bio/alignment
example and test for bio_types::alignment::path()
2 parents e8ce8c9 + a5a28f7 commit bc102fc

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/alignment.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,33 @@ impl Alignment {
326326
}
327327

328328
/// Returns the optimal path in the alignment matrix
329+
///
330+
/// # Example
331+
///
332+
/// ```
333+
/// use bio_types::alignment::{Alignment,AlignmentMode};
334+
/// use bio_types::alignment::AlignmentOperation::*;
335+
/// let alignment = Alignment {
336+
/// score: 5,
337+
/// xstart: 3,
338+
/// ystart: 0,
339+
/// xend: 9,
340+
/// yend: 10,
341+
/// ylen: 10,
342+
/// xlen: 10,
343+
/// operations: vec![Match, Match, Match, Subst, Ins, Ins, Del, Del],
344+
/// mode: AlignmentMode::Semiglobal,
345+
/// };
346+
/// assert_eq!(alignment.path(),[
347+
/// (4, 5, Match),
348+
/// (5, 6, Match),
349+
/// (6, 7, Match),
350+
/// (7, 8, Subst),
351+
/// (8, 8, Ins),
352+
/// (9, 8, Ins),
353+
/// (9, 9, Del),
354+
/// (9, 10, Del)])
355+
/// ```
329356
pub fn path(&self) -> Vec<(usize, usize, AlignmentOperation)> {
330357
let mut path = Vec::new();
331358

@@ -480,4 +507,32 @@ mod tests {
480507
let pretty = concat!(" AAAA--A\n |\\\\+xx \nTTTTTTTT-TT \n\n\n");
481508
assert_eq!(alignment.pretty(b"AAAAA", b"TTTTTTTTTT"), pretty);
482509
}
510+
511+
#[test]
512+
fn test_path() {
513+
let alignment = Alignment {
514+
score: 5,
515+
xstart: 3,
516+
ystart: 0,
517+
xend: 9,
518+
yend: 10,
519+
ylen: 10,
520+
xlen: 10,
521+
operations: vec![Match, Match, Match, Subst, Ins, Ins, Del, Del],
522+
mode: AlignmentMode::Semiglobal,
523+
};
524+
assert_eq!(
525+
alignment.path(),
526+
[
527+
(4, 5, Match),
528+
(5, 6, Match),
529+
(6, 7, Match),
530+
(7, 8, Subst),
531+
(8, 8, Ins),
532+
(9, 8, Ins),
533+
(9, 9, Del),
534+
(9, 10, Del)
535+
]
536+
)
537+
}
483538
}

0 commit comments

Comments
 (0)