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
#[cxx::bridge()]
pub mod recgen {
unsafe extern "C++" {
include!("recgen-sys/src/wrapper.h");
type Config;
fn config_create(
db_filepath: &CxxString,
in_format: &CxxString,
) -> UniquePtr<Config>;
fn config_get_ptable(conf: &UniquePtr<Config>) -> String;
type Frame;
fn frame_create(
db_filepath: &CxxString,
in_filepath: &CxxString,
out_filepath: &CxxString
) -> UniquePtr<Frame>;
fn frame_get_n_units(frame: &UniquePtr<Frame>) -> i32;
fn build_generate_bfs(
db_filepath: &CxxString,
in_filepath: &CxxString,
out_filepath: &CxxString,
verbose: bool
) -> usize;
fn build(
conf: &UniquePtr<Config>,
input: &CxxString,
div_idx: usize,
div_all: usize
) -> Vec<String>;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config() {
cxx::let_cxx_string!(db_filepath = "deps/ReCGen/examples/example.db");
cxx::let_cxx_string!(in_format = "mol");
let conf = recgen::config_create(&db_filepath, &in_format);
assert_eq!(recgen::config_get_ptable(&conf), "frag".to_string());
}
#[test]
fn test_frame_n_unit() {
let results: Vec<i32> = vec![2, 3, 3, 3, 4];
cxx::let_cxx_string!(db_filepath = "deps/ReCGen/examples/example.db");
cxx::let_cxx_string!(out_filepath = "deps/ReCGen/examples/output.smi");
for idx in 0..5 {
cxx::let_cxx_string!(in_filepath = format!("deps/ReCGen/examples/sample{}.mol", idx + 1));
let frame = recgen::frame_create(&db_filepath, &in_filepath, &out_filepath);
assert_eq!(recgen::frame_get_n_units(&frame), results[idx]);
}
}
#[test]
fn test_build_generate_bfs() {
cxx::let_cxx_string!(db_filepath = "../../../data/recgen/DB/DrugBank_M.db");
cxx::let_cxx_string!(out_filepath = "deps/ReCGen/examples/output.smi");
let results: Vec<usize> = vec![1133, 0, 0, 33, 0]; for idx in vec![1, 4] {
cxx::let_cxx_string!(in_filepath = format!("deps/ReCGen/examples/sample{}.mol", idx));
assert_eq!(results[idx - 1], recgen::build_generate_bfs(&db_filepath, &in_filepath, &out_filepath, false));
}
}
}