annotate subsearch.py @ 13:274193d6c443 draft default tip

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 327c29cc43f56d7067ab9fa51323ea31951db98b"
author bgruening
date Tue, 10 Nov 2020 20:32:42 +0000
parents 2912ebf12ef2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
2 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
3 Input: Molecules in SDF, SMILES ...
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
4 Output: Moleculs filtered with specified substructures.
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
5 Copyright 2013, Bjoern Gruening and Xavier Lucas
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
6 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
7 import argparse
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
8 import multiprocessing
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
9 import os
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
10 import shutil
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
11 import subprocess
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
12 import sys
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
13 import tempfile
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
14
11
78640d0127ce "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
bgruening
parents: 0
diff changeset
15 from openbabel import openbabel, pybel
78640d0127ce "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
bgruening
parents: 0
diff changeset
16 openbabel.obErrorLog.StopLogging()
78640d0127ce "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 944ea4bb8a9cd4244152a4a4fecd0485fabc2ad0"
bgruening
parents: 0
diff changeset
17
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
18
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
19 def parse_command_line():
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
20 parser = argparse.ArgumentParser()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
21 parser.add_argument('-i', '--infile', required=True, help='Molecule file.')
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
22 parser.add_argument('--iformat', help='Input format.')
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
23 parser.add_argument('--fastsearch-index', dest="fastsearch_index", required=True,
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
24 help='Path to the openbabel fastsearch index.')
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
25 parser.add_argument('-o', '--outfile', required=True, help='Path to the output file.')
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
26 parser.add_argument('--oformat', default='smi', help='Output file format')
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
27 parser.add_argument("--max-candidates", dest="max_candidates", type=int, default=4000,
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
28 help="The maximum number of candidates.")
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
29 parser.add_argument('-p', '--processors', type=int,
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
30 default=multiprocessing.cpu_count())
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
31 return parser.parse_args()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
32
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
33
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
34 results = list()
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
35
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
36
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
37 def mp_callback(res):
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
38 results.append(res)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
39
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
40
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
41 def mp_helper(query, args):
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
42 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
43 Helper function for multiprocessing.
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
44 That function is a wrapper around the following command:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
45 obabel file.fs -s"smarts" -Ooutfile.smi -al 999999999
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
46 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
47
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
48 if args.oformat == 'names':
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
49 opts = '-osmi -xt'
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
50 else:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
51 opts = '-o%s' % args.oformat
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
52
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
53 tmp = tempfile.NamedTemporaryFile(delete=False)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
54 cmd = 'obabel -ifs %s -O %s %s -s%s -al %s' % (args.fastsearch_index, tmp.name, opts, query, args.max_candidates)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
55
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
56 child = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
57
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
58 stdout, stderr = child.communicate()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
59 return_code = child.returncode
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
60
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
61 if return_code:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
62 sys.stdout.write(stdout)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
63 sys.stderr.write(stderr)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
64 sys.stderr.write("Return error code %i from command:\n" % return_code)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
65 sys.stderr.write("%s\n" % cmd)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
66 else:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
67 sys.stdout.write(stdout)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
68 sys.stdout.write(stderr)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
69 return (tmp.name, query)
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
70
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
71
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
72 def get_smiles_or_smarts(args):
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
73 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
74 Wrapper to retrieve a striped SMILES or SMARTS string from different input formats.
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
75 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
76 if args.iformat in ['smi', 'text', 'tabular']:
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
77 with open(args.infile) as text_file:
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
78 for line in text_file:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
79 yield line.split('\t')[0].strip()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
80 else:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
81 # inchi or sdf files
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
82 for mol in pybel.readfile(args.iformat, args.infile):
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
83 yield mol.write('smiles').split('\t')[0]
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
84
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
85
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
86 def substructure_search(args):
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
87 pool = multiprocessing.Pool(args.processors)
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
88 for query in get_smiles_or_smarts(args):
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
89 pool.apply_async(mp_helper, args=(query, args), callback=mp_callback)
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
90 # mp_callback(mp_helper(query, args))
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
91 pool.close()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
92 pool.join()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
93
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
94 if args.oformat == 'names':
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
95 out_handle = open(args.outfile, 'w')
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
96 for result_file, query in results:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
97 with open(result_file) as res_handle:
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
98 for line in res_handle:
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
99 out_handle.write('%s\t%s\n' % (line.strip(), query))
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
100 os.remove(result_file)
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
101 out_handle.close()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
102 else:
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
103 out_handle = open(args.outfile, 'wb')
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
104 for result_file, query in results:
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
105 res_handle = open(result_file, 'rb')
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
106 shutil.copyfileobj(res_handle, out_handle)
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
107 res_handle.close()
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
108 os.remove(result_file)
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
109 out_handle.close()
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
110
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
111
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
112 def __main__():
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
113 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
114 Multiprocessing Open Babel Substructure Search.
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
115 """
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
116 args = parse_command_line()
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
117 substructure_search(args)
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
118
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
119
12
2912ebf12ef2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
bgruening
parents: 11
diff changeset
120 if __name__ == "__main__":
0
b0311f002a5f planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 8350bb3a632722c33bc91ec5238d47a536903729
bgruening
parents:
diff changeset
121 __main__()