File: example.rs

package info (click to toggle)
libwfa2 2.3.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,072 kB
  • sloc: ansic: 13,812; python: 540; cpp: 500; makefile: 268; sh: 176; lisp: 41
file content (46 lines) | stat: -rw-r--r-- 1,659 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/// Include the generated bindings into a separate module.
#[allow(non_upper_case_globals)]
#[allow(non_snake_case)]
#[allow(non_camel_case_types)]
#[allow(unused)]
mod wfa {
    include!(concat!(env!("OUT_DIR"), "/bindings_wfa.rs"));
}

/// Compute the affine alignment score between `a` and `b` with the given substitution,
/// gap-open, and gap-extend penalties.
fn linear_score(a: &[i8], b: &[i8], sub: i32, indel: i32) -> i32 {
    unsafe {
        let mut attributes = wfa::wavefront_aligner_attr_default;
        // Do not use a heuristic (enabled by default).
        attributes.heuristic.strategy = wfa::wf_heuristic_strategy_wf_heuristic_none;
        // Only compute the score (not a path).
        attributes.alignment_scope = wfa::alignment_scope_t_compute_score;

        // Set the cost model and parameters.
        attributes.distance_metric = wfa::distance_metric_t_gap_affine;
        attributes.affine_penalties.mismatch = mismatch as i32;
        attributes.affine_penalties.gap_opening = gap_open as i32;
        attributes.affine_penalties.gap_extension = gap_extend as i32;

        // Initialize the aligner object.
        // This should be reused for multiple queries.
        let wf_aligner = wfa::wavefront_aligner_new(&mut attributes);

        // Do the alignment.
        let status = wfa::wavefront_align(
            wf_aligner,
            a.as_ptr(),
            a.len() as i32,
            b.as_ptr(),
            b.len() as i32,
        );
        assert_eq!(status, 0);

        let score = (*wf_aligner).cigar.score;

        // Clean up memory.
        wfa::wavefront_aligner_delete(wf_aligner);
        score
    }
}