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
mod doc;
mod source;
pub use doc::smiles::DocSMILES;
pub use doc::smiles::DocStoreSMILES;
pub use source::chembl::SourceChembl;
pub trait Dummy {
fn dummy() -> Self;
}
pub trait Info {
fn info(&self) -> String;
}
pub fn load_from_path<T: Dummy + From<SourceChembl>>(kind: &chiral_common::kinds::Dataset, filepath: &std::path::PathBuf) -> T {
match kind {
chiral_common::kinds::Dataset::Dummy => T::dummy(),
chiral_common::kinds::Dataset::TestChembl | chiral_common::kinds::Dataset::Chembl30 => {
let mut sc = SourceChembl::new();
sc.set_path(filepath.as_os_str());
sc.load_all();
T::from(sc)
}
}
}
pub fn load<T: Dummy + From<SourceChembl>>(kind: &chiral_common::kinds::Dataset) -> T {
match kind {
chiral_common::kinds::Dataset::Dummy => T::dummy(),
chiral_common::kinds::Dataset::TestChembl | chiral_common::kinds::Dataset::Chembl30 => {
let mut sc = SourceChembl::new();
let filepath = chiral_common::fs::default_dir().join(kind.filename());
sc.set_path(filepath.as_os_str());
sc.load_all();
T::from(sc)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_load() {
let filepath = std::path::PathBuf::from("../../../chiral-db-example-data/ChEMBL/chembl_30_chemreps_100.txt");
let doc_1 = load_from_path::<doc::smiles::DocSMILES>(&chiral_common::kinds::Dataset::TestChembl, &filepath);
assert_eq!(doc_1.get_ids().len(), 100);
assert_eq!(doc_1.get_smiles_vec().len(), 100);
let doc_2 = load::<doc::smiles::DocSMILES>(&chiral_common::kinds::Dataset::TestChembl);
assert_eq!(doc_2.get_ids().len(), 10000);
assert_eq!(doc_2.get_smiles_vec().len(), 10000);
}
}