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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
use std::ffi::{CStr, c_void};
use std::os::raw::c_char;
use crate::scan_block::*;
use crate::scores::*;
use crate::cigar::OpLen;
pub type BlockHandle = *mut c_void;
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub struct SizeRange {
pub min: usize,
pub max: usize
}
#[repr(C)]
pub struct CigarVec {
pub ptr: *mut OpLen,
pub len: usize,
pub cap: usize
}
#[no_mangle]
pub unsafe extern fn block_make_padded_aa(s: *const c_char, max_size: usize) -> *mut PaddedBytes {
let c_str = CStr::from_ptr(s);
let padded_bytes = Box::new(PaddedBytes::from_bytes::<AAMatrix>(c_str.to_bytes(), max_size));
Box::into_raw(padded_bytes)
}
#[no_mangle]
pub unsafe extern fn block_free_padded_aa(padded: *mut PaddedBytes) {
drop(Box::from_raw(padded));
}
#[no_mangle]
pub unsafe extern fn block_free_cigar(v: CigarVec) {
drop(Vec::from_raw_parts(v.ptr, v.len, v.cap));
}
#[no_mangle]
pub unsafe extern fn block_align_aa(q: *const PaddedBytes,
r: *const PaddedBytes,
m: *const AAMatrix,
g: Gaps,
s: SizeRange) -> BlockHandle {
let aligner = Box::new(Block::<_, false, false>::align(&*q, &*r, &*m, g, s.min..=s.max, 0));
Box::into_raw(aligner) as BlockHandle
}
#[no_mangle]
pub unsafe extern fn block_res_aa(b: BlockHandle) -> AlignResult {
let aligner = &*(b as *const Block<AAMatrix, false, false>);
aligner.res()
}
#[no_mangle]
pub unsafe extern fn block_free_aa(b: BlockHandle) {
drop(Box::from_raw(b as *mut Block<AAMatrix, false, false>));
}
#[no_mangle]
pub unsafe extern fn block_align_aa_xdrop(q: *const PaddedBytes,
r: *const PaddedBytes,
m: *const AAMatrix,
g: Gaps,
s: SizeRange,
x: i32) -> BlockHandle {
let aligner = Box::new(Block::<_, false, true>::align(&*q, &*r, &*m, g, s.min..=s.max, x));
Box::into_raw(aligner) as BlockHandle
}
#[no_mangle]
pub unsafe extern fn block_res_aa_xdrop(b: BlockHandle) -> AlignResult {
let aligner = &*(b as *const Block<AAMatrix, false, true>);
aligner.res()
}
#[no_mangle]
pub unsafe extern fn block_free_aa_xdrop(b: BlockHandle) {
drop(Box::from_raw(b as *mut Block<AAMatrix, false, true>));
}
#[no_mangle]
pub unsafe extern fn block_align_aa_trace(q: *const PaddedBytes,
r: *const PaddedBytes,
m: *const AAMatrix,
g: Gaps,
s: SizeRange) -> BlockHandle {
let aligner = Box::new(Block::<_, true, false>::align(&*q, &*r, &*m, g, s.min..=s.max, 0));
Box::into_raw(aligner) as BlockHandle
}
#[no_mangle]
pub unsafe extern fn block_res_aa_trace(b: BlockHandle) -> AlignResult {
let aligner = &*(b as *const Block<AAMatrix, true, false>);
aligner.res()
}
#[no_mangle]
pub unsafe extern fn block_cigar_aa_trace(b: BlockHandle) -> CigarVec {
let aligner = &*(b as *const Block<AAMatrix, true, false>);
let res = aligner.res();
let cigar_vec = aligner.trace().cigar(res.query_idx, res.reference_idx).to_vec();
let (ptr, len, cap) = cigar_vec.into_raw_parts();
CigarVec { ptr, len, cap }
}
#[no_mangle]
pub unsafe extern fn block_free_aa_trace(b: BlockHandle) {
drop(Box::from_raw(b as *mut Block<AAMatrix, true, false>));
}
#[no_mangle]
pub unsafe extern fn block_align_aa_trace_xdrop(q: *const PaddedBytes,
r: *const PaddedBytes,
m: *const AAMatrix,
g: Gaps,
s: SizeRange,
x: i32) -> BlockHandle {
let aligner = Box::new(Block::<_, true, true>::align(&*q, &*r, &*m, g, s.min..=s.max, x));
Box::into_raw(aligner) as BlockHandle
}
#[no_mangle]
pub unsafe extern fn block_res_aa_trace_xdrop(b: BlockHandle) -> AlignResult {
let aligner = &*(b as *const Block<AAMatrix, true, true>);
aligner.res()
}
#[no_mangle]
pub unsafe extern fn block_cigar_aa_trace_xdrop(b: BlockHandle) -> CigarVec {
let aligner = &*(b as *const Block<AAMatrix, true, true>);
let res = aligner.res();
let cigar_vec = aligner.trace().cigar(res.query_idx, res.reference_idx).to_vec();
let (ptr, len, cap) = cigar_vec.into_raw_parts();
CigarVec { ptr, len, cap }
}
#[no_mangle]
pub unsafe extern fn block_free_aa_trace_xdrop(b: BlockHandle) {
drop(Box::from_raw(b as *mut Block<AAMatrix, true, true>));
}