Mercurial > repos > bgruening > openbabel_remions
comparison ob_genProp.py @ 13:3153b6f3087c draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
author | bgruening |
---|---|
date | Mon, 19 Oct 2020 14:43:01 +0000 |
parents | 354c048550f7 |
children | f70b83b730ac |
comparison
equal
deleted
inserted
replaced
12:354c048550f7 | 13:3153b6f3087c |
---|---|
2 """ | 2 """ |
3 Input: Molecular input file. | 3 Input: Molecular input file. |
4 Output: Physico-chemical properties are computed and stored as metadata in the sdf output file. | 4 Output: Physico-chemical properties are computed and stored as metadata in the sdf output file. |
5 Copyright 2012, Bjoern Gruening and Xavier Lucas | 5 Copyright 2012, Bjoern Gruening and Xavier Lucas |
6 """ | 6 """ |
7 import sys, os | |
8 import argparse | 7 import argparse |
8 import sys | |
9 | |
10 import cheminfolib | |
9 import openbabel | 11 import openbabel |
12 from openbabel import pybel | |
10 openbabel.obErrorLog.StopLogging() | 13 openbabel.obErrorLog.StopLogging() |
11 import cheminfolib | |
12 | 14 |
13 from openbabel import pybel | |
14 | 15 |
15 def parse_command_line(argv): | 16 def parse_command_line(argv): |
16 parser = argparse.ArgumentParser() | 17 parser = argparse.ArgumentParser() |
17 parser.add_argument('--iformat', default='sdf' , help='input file format') | 18 parser.add_argument('--iformat', default='sdf', help='input file format') |
18 parser.add_argument('-i', '--input', required=True, help='input file name') | 19 parser.add_argument('-i', '--input', required=True, help='input file name') |
19 parser.add_argument('--oformat', default='sdf', choices = ['sdf', 'table'] , help='output file format') | 20 parser.add_argument('--oformat', default='sdf', choices=['sdf', 'table'], help='output file format') |
20 parser.add_argument('--header', type=bool, help='Include the header as the first line of the output table') | 21 parser.add_argument('--header', type=bool, help='Include the header as the first line of the output table') |
21 parser.add_argument('-o', '--output', required=True, help='output file name') | 22 parser.add_argument('-o', '--output', required=True, help='output file name') |
22 return parser.parse_args() | 23 return parser.parse_args() |
24 | |
23 | 25 |
24 def compute_properties(args): | 26 def compute_properties(args): |
25 if args.oformat == 'sdf': | 27 if args.oformat == 'sdf': |
26 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True) | 28 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True) |
27 else: | 29 else: |
28 outfile = open(args.output, 'w') | 30 outfile = open(args.output, 'w') |
29 if args.header: | 31 if args.header: |
30 mol = next(pybel.readfile(args.iformat, args.input)) | 32 mol = next(pybel.readfile(args.iformat, args.input)) |
31 metadata = cheminfolib.get_properties_ext(mol) | 33 metadata = cheminfolib.get_properties_ext(mol) |
32 outfile.write( '%s\n' % '\t'.join( [ cheminfolib.ColumnNames[key] for key in metadata ] ) ) | 34 outfile.write('%s\n' % '\t'.join([cheminfolib.ColumnNames[key] for key in metadata])) |
33 | 35 |
34 for mol in pybel.readfile(args.iformat, args.input): | 36 for mol in pybel.readfile(args.iformat, args.input): |
35 if mol.OBMol.NumHvyAtoms() > 5: | 37 if mol.OBMol.NumHvyAtoms() > 5: |
36 metadata = cheminfolib.get_properties_ext(mol) | 38 metadata = cheminfolib.get_properties_ext(mol) |
37 if args.oformat == 'sdf': | 39 if args.oformat == 'sdf': |
38 [ mol.data.update( { cheminfolib.ColumnNames[key] : metadata[key] } ) for key in metadata ] | 40 [mol.data.update({cheminfolib.ColumnNames[key]: metadata[key]}) for key in metadata] |
39 outfile.write(mol) | 41 outfile.write(mol) |
40 else: | 42 else: |
41 outfile.write( '%s\n' % ('\t'.join( [ str(metadata[key]) for key in metadata ] ) ) ) | 43 outfile.write('%s\n' % ('\t'.join([str(metadata[key]) for key in metadata]))) |
42 outfile.close() | 44 outfile.close() |
45 | |
43 | 46 |
44 def __main__(): | 47 def __main__(): |
45 """ | 48 """ |
46 Physico-chemical properties are computed and stored as metadata in the sdf output file | 49 Physico-chemical properties are computed and stored as metadata in the sdf output file |
47 """ | 50 """ |
48 args = parse_command_line(sys.argv) | 51 args = parse_command_line(sys.argv) |
49 compute_properties(args) | 52 compute_properties(args) |
50 | 53 |
51 if __name__ == "__main__" : | 54 |
55 if __name__ == "__main__": | |
52 __main__() | 56 __main__() |