-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_pains.cpp
105 lines (80 loc) · 3 KB
/
find_pains.cpp
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
#include <iostream>
#include <map>
#include <string>
#include <openbabel/obconversion.h>
#include <openbabel/mol.h>
#include <fstream>
#include <regex>
using namespace std;
using namespace OpenBabel;
map<string, string> get_smarts_from_file (string);
map<int, string> get_smiles_from_file (string);
int main(int argc,char **argv) {
OBConversion conv;
conv.SetInFormat("smiles");
OBMol mol;
//Load the SMILES string of the parent molecules and 3 smarts patterns files into memory
map<int, string> molmap = get_smiles_from_file ( argv[1] );
map<string, string> ffa = get_smarts_from_file( argv[2] );
map<string, string> ffb = get_smarts_from_file( argv[3] );
map<string, string> ffc = get_smarts_from_file( argv[4] );
//Iterate over SMILES targets and SMARTS fingerprints
for (map<int, string>::iterator itt = molmap.begin(); itt != molmap.end(); itt++) {
static int c = 0;
conv.ReadString(&mol, itt->second);
for (map<string, string>::iterator it = ffa.begin(); it != ffa.end(); it++) {
OBSmartsPattern sm;
sm.Init(it->second);
if ( sm.IsValid() and sm.HasMatch(mol) )
cout << "Found a match: " << it->first << " Parent mol: " << itt->second << "\n";
}
for (map<string, string>::iterator it = ffb.begin(); it != ffb.end(); it++) {
OBSmartsPattern sm;
sm.Init(it->second);
if ( sm.IsValid() and sm.HasMatch(mol) )
cout << "Found a match: " << it->first << " Parent mol: " << itt->second << "\n";
}
for (map<string, string>::iterator it = ffc.begin(); it != ffc.end(); it++) {
OBSmartsPattern sm;
sm.Init(it->second);
if ( sm.IsValid() and sm.HasMatch(mol) )
cout << "Found a match: " << it->first << " Parent mol: " << itt->second << "\n";
}
c+=1;
if (c>=5000)
break;
}
return(0);
}
//function definitions
map<string, string> get_smarts_from_file (string input) {
map<string, string> res;
string eachLine;
ifstream theFile ( input );
const regex smarts_regex{"(FRAGMENT\\s+regId=(\\S+)\\(\\d+\\)\\s+(\\S+).*)"};
if (!theFile.is_open() )
cout << "Error, couldnt open smarts pattern file\n";
while (getline (theFile, eachLine) ) {
smatch match;
regex_search(eachLine, match, smarts_regex);
res[match[2]] = match[3];
}
theFile.close();
return res;
}
map<int, string> get_smiles_from_file (string input) {
static int count = 0;
map<int, string> res;
string eachLine;
ifstream theFile ( input );
const regex r{"(\\d+)\\s+(.*)"};
if (!theFile.is_open() )
cout << "Error, couldnt open smarts pattern file\n";
while (getline (theFile, eachLine) ) {
smatch match;
regex_search(eachLine, match, r);
res[count++] = match[2];
}
theFile.close();
return res;
}