Mercurial > repos > bgruening > openbabel_addh
annotate multi_obgrep.py @ 11:449c3def61cc draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit cda909c5e0b88fa3d12abe43fc72b8dd0729417a"
| author | bgruening | 
|---|---|
| date | Thu, 09 Apr 2020 13:53:21 +0000 | 
| parents | c6f3cedfe301 | 
| children | 9a08f0d1b305 | 
| rev | line source | 
|---|---|
| 
0
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
2 """ | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
3 Input: Molecules in SDF, SMILES ... | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
4 Output: Molecule file filtered with obgrep. | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
5 Copyright 2013, Bjoern Gruening and Xavier Lucas | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
6 """ | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
7 import sys, os | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
8 import argparse | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
9 import openbabel | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
10 openbabel.obErrorLog.StopLogging() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
11 import pybel | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
12 import multiprocessing | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
13 import tempfile | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
14 import subprocess | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
15 import shutil | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
16 import shlex | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
17 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
18 def parse_command_line(): | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
19 parser = argparse.ArgumentParser() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
20 parser.add_argument('-i', '--infile', required=True, help='Molecule file.') | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
21 parser.add_argument('-q', '--query', required=True, help='Query file, containing different SMARTS in each line.') | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
22 parser.add_argument('-o', '--outfile', required=True, help='Path to the output file.') | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
23 parser.add_argument("--iformat", help="Input format, like smi, sdf, inchi") | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
24 parser.add_argument("--n-times", dest="n_times", type=int, | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
25 default=0, help="Print a molecule only if the pattern occurs # times inside the molecule.") | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
26 parser.add_argument('-p', '--processors', type=int, default=multiprocessing.cpu_count()) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
27 parser.add_argument("--invert-matches", dest="invert_matches", action="store_true", | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
28 default=False, help="Invert the matching, print non-matching molecules.") | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
29 parser.add_argument("--only-name", dest="only_name", action="store_true", | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
30 default=False, help="Only print the name of the molecules.") | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
31 parser.add_argument("--full-match", dest="full_match", action="store_true", | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
32 default=False, help="Full match, print matching-molecules only when the number of heavy atoms is also equal to the number of atoms in the SMARTS pattern.") | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
33 parser.add_argument("--number-of-matches", dest="number_of_matches", action="store_true", | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
34 default=False, help="Print the number of matches.") | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
35 return parser.parse_args() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
36 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
37 results = list() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
38 def mp_callback(res): | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
39 results.append(res) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
40 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
41 def mp_helper( query, args ): | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
42 """ | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
43 Helper function for multiprocessing. | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
44 That function is a wrapper around obgrep. | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
45 """ | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
46 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
47 cmd_list = [] | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
48 if args.invert_matches: | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
49 cmd_list.append('-v') | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
50 if args.only_name: | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
51 cmd_list.append('-n') | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
52 if args.full_match: | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
53 cmd_list.append('-f') | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
54 if args.number_of_matches: | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
55 cmd_list.append('-c') | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
56 if args.n_times: | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
57 cmd_list.append('-t %s' % str(args.n_times)) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
58 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
59 tmp = tempfile.NamedTemporaryFile(delete=False) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
60 cmd = 'obgrep %s "%s" %s' % (' '.join(cmd_list), query, args.infile) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
61 child = subprocess.Popen(shlex.split(cmd), | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
62 stdout=open(tmp.name, 'w+'), stderr=subprocess.PIPE) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
63 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
64 stdout, stderr = child.communicate() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
65 return (tmp.name, query) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
66 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
67 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
68 def obgrep( args ): | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
69 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
70 temp_file = tempfile.NamedTemporaryFile() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
71 temp_link = "%s.%s" % (temp_file.name, args.iformat) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
72 temp_file.close() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
73 os.symlink(args.infile, temp_link) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
74 args.infile = temp_link | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
75 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
76 pool = multiprocessing.Pool( args.processors ) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
77 for query in open( args.query ): | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
78 pool.apply_async(mp_helper, args=(query.strip(), args), callback=mp_callback) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
79 #mp_callback( mp_helper(query.strip(), args) ) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
80 pool.close() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
81 pool.join() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
82 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
83 out_handle = open( args.outfile, 'wb' ) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
84 for result_file, query in results: | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
85 res_handle = open(result_file,'rb') | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
86 shutil.copyfileobj( res_handle, out_handle ) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
87 res_handle.close() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
88 os.remove( result_file ) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
89 out_handle.close() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
90 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
91 os.remove( temp_link ) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
92 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
93 def __main__(): | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
94 """ | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
95 Multiprocessing obgrep search. | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
96 """ | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
97 args = parse_command_line() | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
98 obgrep( args ) | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
99 | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
100 if __name__ == "__main__" : | 
| 
 
c6f3cedfe301
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
 
bgruening 
parents:  
diff
changeset
 | 
101 __main__() | 
