-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathfilter_mols.py
executable file
·37 lines (26 loc) · 1.14 KB
/
filter_mols.py
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
#!/usr/bin/env python3
__author__ = 'Pavel Polishchuk'
import argparse
def filter_mols(input_fname, output_fname, names_fname):
with open(names_fname)as f:
names = {line.strip() for line in f}
with open(input_fname) as f_in, open(output_fname, 'wt') as f_out:
molstr = []
for line in f_in:
molstr.append(line)
if line.strip() == '$$$$':
if molstr[0].strip() in names:
f_out.writelines(molstr)
molstr = []
def main():
parser = argparse.ArgumentParser(description='Filter input molecules by names.')
parser.add_argument('-i', '--input', metavar='FILENAME', required=True, type=str,
help='input SDF file.')
parser.add_argument('-o', '--output', metavar='FILENAME', required=True, type=str,
help='output SDF file.')
parser.add_argument('-n', '--names', metavar='FILENAME', required=True, type=str,
help='text file with molecule names to keep.')
args = parser.parse_args()
filter_mols(args.input, args.output, args.names)
if __name__ == '__main__':
main()