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
use crate::errors::*;
use std::str::FromStr;
pub fn dataset(matches: &clap::ArgMatches) -> Result<chiral_common::kinds::Dataset> {
let dsk_string = matches.get_one::<String>("dataset").unwrap();
chiral_common::kinds::Dataset::from_str(dsk_string).map_err(|e| e.into())
}
pub fn dataset_kind(matches: &clap::ArgMatches) -> Result<chiral_common::kinds::Dataset> {
let dsk_string = matches.get_one::<String>("kind").unwrap();
chiral_common::kinds::Dataset::from_str(dsk_string).map_err(|e| e.into())
}
pub fn operator(matches: &clap::ArgMatches) -> Result<chiral_common::kinds::Operator> {
let opk_string = matches.get_one::<String>("operator").unwrap();
chiral_common::kinds::Operator::from_str(opk_string)
.map_err(|e| e.into())
}
pub fn smiles(matches: &clap::ArgMatches) -> Result<&chiral_common::SMILES> {
matches.get_one::<String>("smiles").ok_or("Get SMILES error!")
.map_err(|e| e.into())
}
pub fn threshold(matches: &clap::ArgMatches) -> Result<f32> {
let th_str = matches.get_one::<String>("threshold").unwrap();
th_str.parse().or(Err(format!("Cannot convert {} to f32", th_str)))
.map_err(|e| e.into())
}
pub fn fingerprint(matches: &clap::ArgMatches) -> Result<chiral_common::kinds::Fingerprint> {
let fpk_string = matches.get_one::<String>("fingerprint").unwrap();
chiral_common::kinds::Fingerprint::from_str(fpk_string)
.map_err(|e| e.into())
}
pub fn save(matches: &clap::ArgMatches) -> bool {
*matches.get_one::<bool>("save").unwrap()
}
pub fn id(matches: &clap::ArgMatches) -> Result<&String> {
matches.get_one::<String>("id").ok_or("Get id error!")
.map_err(|e| e.into())
}
pub enum InputForOperator {
OpenBabelSimilariy { smiles: chiral_common::SMILES, fpk: chiral_common::kinds::Fingerprint, threshold: f32, is_save: bool },
OpenBabelSsMatch { smiles: chiral_common::SMILES, is_save: bool }
}
pub fn ob_similarity(matches: &clap::ArgMatches) -> Result<InputForOperator> {
let smiles = smiles(matches)?.to_string();
let fpk = fingerprint(matches)?;
let threshold = threshold(matches)?;
let is_save = save(matches);
Ok(InputForOperator::OpenBabelSimilariy { smiles, fpk, threshold, is_save })
}
pub fn ob_ss_match(matches: &clap::ArgMatches) -> Result<InputForOperator> {
let smiles = smiles(matches)?.to_string();
let is_save = save(matches);
Ok(InputForOperator::OpenBabelSsMatch { smiles, is_save })
}
pub fn get_input(matches: &clap::ArgMatches) -> Result<InputForOperator> {
let opk = operator(matches)?;
match opk {
chiral_common::kinds::Operator::OpenBabelSimilaritySearching => Ok(ob_similarity(matches)?),
chiral_common::kinds::Operator::OpenBabelSSMatching => Ok(ob_ss_match(matches)?)
}
}