comparison ob_genProp.py @ 15:81836d586797 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit d9c51279c061a1da948a2582d5b502ca7573adbf
author bgruening
date Thu, 15 Aug 2024 11:01:36 +0000
parents e94b2920d4e4
children
comparison
equal deleted inserted replaced
14:d7f0ca1f2669 15:81836d586797
8 import sys 8 import sys
9 9
10 import cheminfolib 10 import cheminfolib
11 import openbabel 11 import openbabel
12 from openbabel import pybel 12 from openbabel import pybel
13
13 openbabel.obErrorLog.StopLogging() 14 openbabel.obErrorLog.StopLogging()
14 15
15 16
16 def parse_command_line(argv): 17 def parse_command_line(argv):
17 parser = argparse.ArgumentParser() 18 parser = argparse.ArgumentParser()
18 parser.add_argument('--iformat', default='sdf', help='input file format') 19 parser.add_argument("--iformat", default="sdf", help="input file format")
19 parser.add_argument('-i', '--input', required=True, help='input file name') 20 parser.add_argument("-i", "--input", required=True, help="input file name")
20 parser.add_argument('--oformat', default='sdf', choices=['sdf', 'table'], help='output file format') 21 parser.add_argument(
21 parser.add_argument('--header', type=bool, help='Include the header as the first line of the output table') 22 "--oformat", default="sdf", choices=["sdf", "table"], help="output file format"
22 parser.add_argument('-o', '--output', required=True, help='output file name') 23 )
24 parser.add_argument(
25 "--header",
26 type=bool,
27 help="Include the header as the first line of the output table",
28 )
29 parser.add_argument("-o", "--output", required=True, help="output file name")
23 return parser.parse_args() 30 return parser.parse_args()
24 31
25 32
26 def compute_properties(args): 33 def compute_properties(args):
27 if args.oformat == 'sdf': 34 if args.oformat == "sdf":
28 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True) 35 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True)
29 else: 36 else:
30 outfile = open(args.output, 'w') 37 outfile = open(args.output, "w")
31 if args.header: 38 if args.header:
32 mol = next(pybel.readfile(args.iformat, args.input)) 39 mol = next(pybel.readfile(args.iformat, args.input))
33 metadata = cheminfolib.get_properties_ext(mol) 40 metadata = cheminfolib.get_properties_ext(mol)
34 outfile.write('%s\n' % '\t'.join([cheminfolib.ColumnNames[key] for key in metadata])) 41 outfile.write(
42 "%s\n" % "\t".join([cheminfolib.ColumnNames[key] for key in metadata])
43 )
35 44
36 for mol in pybel.readfile(args.iformat, args.input): 45 for mol in pybel.readfile(args.iformat, args.input):
37 if mol.OBMol.NumHvyAtoms() > 5: 46 if mol.OBMol.NumHvyAtoms() > 5:
38 metadata = cheminfolib.get_properties_ext(mol) 47 metadata = cheminfolib.get_properties_ext(mol)
39 if args.oformat == 'sdf': 48 if args.oformat == "sdf":
40 [mol.data.update({cheminfolib.ColumnNames[key]: metadata[key]}) for key in metadata] 49 [
50 mol.data.update({cheminfolib.ColumnNames[key]: metadata[key]})
51 for key in metadata
52 ]
41 outfile.write(mol) 53 outfile.write(mol)
42 else: 54 else:
43 outfile.write('%s\n' % ('\t'.join([str(metadata[key]) for key in metadata]))) 55 outfile.write(
56 "%s\n" % ("\t".join([str(metadata[key]) for key in metadata]))
57 )
44 outfile.close() 58 outfile.close()
45 59
46 60
47 def __main__(): 61 def __main__():
48 """ 62 """
49 Physico-chemical properties are computed and stored as metadata in the sdf output file 63 Physico-chemical properties are computed and stored as metadata in the sdf output file
50 """ 64 """
51 args = parse_command_line(sys.argv) 65 args = parse_command_line(sys.argv)
52 compute_properties(args) 66 compute_properties(args)
53 67
54 68