annotate subsearch.py @ 0:06340f46ecb8 draft

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