|
a |
|
b/bin/oddt_debug |
|
|
1 |
#!/usr/bin/env python |
|
|
2 |
# -*- coding: utf-8 -*- |
|
|
3 |
from __future__ import print_function |
|
|
4 |
import sys |
|
|
5 |
import argparse |
|
|
6 |
import csv |
|
|
7 |
import gzip |
|
|
8 |
|
|
|
9 |
import six |
|
|
10 |
|
|
|
11 |
import oddt |
|
|
12 |
|
|
|
13 |
# arguments |
|
|
14 |
parser = argparse.ArgumentParser(description='Open Drug Discovery (ODDT) command line tools') |
|
|
15 |
parser.add_argument('--toolkit', dest='toolkit', choices=['ob', 'rdk'], default='ob', help='Choose which toolkit should be used for calculations, either "ob" (OpenBabel) or "rdkit" (RDKit) (default: ob)') |
|
|
16 |
parser.add_argument('--version', action='version', version='%(prog)s ' + oddt.__version__) |
|
|
17 |
|
|
|
18 |
# in/out files and formats |
|
|
19 |
parser.add_argument('in_file', nargs='+', help='Input files of formats supported by toolkit.') |
|
|
20 |
parser.add_argument('-i', dest='in_format', help='Input file(s) format') |
|
|
21 |
parser.add_argument('-O', '--output', dest='out_file', help='Output file') |
|
|
22 |
|
|
|
23 |
# descriptors |
|
|
24 |
group = parser.add_argument_group('Generate CSV from descriptors, scoring functions and docking software') |
|
|
25 |
group.add_argument('--descriptors', |
|
|
26 |
choices=['autodock_vina', |
|
|
27 |
'oddt_vina', |
|
|
28 |
'nnscore', |
|
|
29 |
'binana', |
|
|
30 |
'rfscore_v1', |
|
|
31 |
'rfscore_v2', |
|
|
32 |
'rfscore_v3', |
|
|
33 |
], |
|
|
34 |
help='Choose docking software to be used', |
|
|
35 |
) |
|
|
36 |
group.add_argument('--receptor', help='Protein file') |
|
|
37 |
|
|
|
38 |
args = parser.parse_args() |
|
|
39 |
|
|
|
40 |
|
|
|
41 |
# Switch toolkits |
|
|
42 |
if 'toolkit' in args: |
|
|
43 |
if args.toolkit == 'ob': |
|
|
44 |
from oddt.toolkits import ob |
|
|
45 |
oddt.toolkit = ob |
|
|
46 |
elif args.toolkit == 'rdk': |
|
|
47 |
from oddt.toolkits import rdk |
|
|
48 |
oddt.toolkit = rdk |
|
|
49 |
|
|
|
50 |
# load protein once |
|
|
51 |
if args.receptor: |
|
|
52 |
extension = args.receptor.split('.')[-1] |
|
|
53 |
receptor = six.next(oddt.toolkit.readfile(extension, args.receptor)) |
|
|
54 |
receptor.protein = True |
|
|
55 |
|
|
|
56 |
# Load descriptor genearator |
|
|
57 |
if args.descriptors.startswith('rfscore'): |
|
|
58 |
from oddt.scoring.functions import rfscore |
|
|
59 |
descriptor_generator = rfscore(protein=receptor, version=int(args.descriptors.split('_')[1][1:])).descriptor_generator |
|
|
60 |
elif args.descriptors == 'nnscore': |
|
|
61 |
from oddt.scoring.functions import nnscore |
|
|
62 |
descriptor_generator = nnscore(protein=receptor).descriptor_generator |
|
|
63 |
elif args.descriptors == 'binana': |
|
|
64 |
from oddt.scoring.descriptors.binana import binana_descriptor |
|
|
65 |
descriptor_generator = binana_descriptor(protein=receptor) |
|
|
66 |
elif args.descriptors == 'autodock_vina': |
|
|
67 |
from oddt.scoring.descriptors import autodock_vina_descriptor |
|
|
68 |
descriptor_generator = autodock_vina_descriptor(protein=receptor) |
|
|
69 |
elif args.descriptors == 'oddt_vina': |
|
|
70 |
from oddt.scoring.descriptors import oddt_vina_descriptor |
|
|
71 |
descriptor_generator = oddt_vina_descriptor(protein=receptor) |
|
|
72 |
|
|
|
73 |
assert descriptor_generator is not None, 'No descriptor generator has been chosen.' |
|
|
74 |
|
|
|
75 |
if args.out_file: |
|
|
76 |
if args.out_file.split('.')[-1] == 'gz': |
|
|
77 |
out_file = gzip.open(args.out_file, 'wb+') |
|
|
78 |
else: |
|
|
79 |
out_file = open(args.out_file, 'wb+') |
|
|
80 |
else: |
|
|
81 |
out_file = sys.stdout |
|
|
82 |
|
|
|
83 |
# Print header if possible |
|
|
84 |
if hasattr(descriptor_generator, 'titles'): |
|
|
85 |
print(','.join(descriptor_generator.titles), file=out_file) |
|
|
86 |
|
|
|
87 |
# Read files |
|
|
88 |
for in_file in args.in_file: |
|
|
89 |
if args.in_format: |
|
|
90 |
fmt = args.out_format |
|
|
91 |
else: # autodiscover |
|
|
92 |
tmp = in_file.split('.') |
|
|
93 |
if tmp[-1] == 'gz': |
|
|
94 |
fmt = tmp[-2] |
|
|
95 |
else: |
|
|
96 |
fmt = tmp[-1] |
|
|
97 |
for mol in oddt.toolkit.readfile(fmt, in_file): |
|
|
98 |
if mol: |
|
|
99 |
print(','.join(map(str, descriptor_generator.build([mol]).tolist()[0])), file=out_file) |
|
|
100 |
|
|
|
101 |
if args.out_file: |
|
|
102 |
out_file.close() |