comparison ob_genProp.py @ 0:7133973beaf0 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 01da22e4184a5a6f6a3dd4631a7b9c31d1b6d502
author bgruening
date Sat, 20 May 2017 08:40:10 -0400
parents
children afd14e10a318
comparison
equal deleted inserted replaced
-1:000000000000 0:7133973beaf0
1 #!/usr/bin/env python
2 """
3 Input: Molecular input 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
6 """
7 import sys, os
8 import argparse
9 import openbabel
10 openbabel.obErrorLog.StopLogging()
11 import pybel
12 import cheminfolib
13
14
15 def parse_command_line(argv):
16 parser = argparse.ArgumentParser()
17 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('--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('-o', '--output', required=True, help='output file name')
22 return parser.parse_args()
23
24 def compute_properties(args):
25 if args.oformat == 'sdf':
26 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True)
27 else:
28 outfile = open(args.output, 'w')
29 if args.header:
30 mol = next(pybel.readfile(args.iformat, args.input))
31 metadata = cheminfolib.get_properties_ext(mol)
32 outfile.write( '%s\n' % '\t'.join( [ cheminfolib.ColumnNames[key] for key in metadata ] ) )
33
34 for mol in pybel.readfile(args.iformat, args.input):
35 if mol.OBMol.NumHvyAtoms() > 5:
36 metadata = cheminfolib.get_properties_ext(mol)
37 if args.oformat == 'sdf':
38 [ mol.data.update( { cheminfolib.ColumnNames[key] : metadata[key] } ) for key in metadata ]
39 outfile.write(mol)
40 else:
41 outfile.write( '%s\n' % ('\t'.join( [ str(metadata[key]) for key in metadata ] ) ) )
42 outfile.close()
43
44 def __main__():
45 """
46 Physico-chemical properties are computed and stored as metadata in the sdf output file
47 """
48 args = parse_command_line(sys.argv)
49 compute_properties(args)
50
51 if __name__ == "__main__" :
52 __main__()