comparison ob_filter.py @ 11:854a7a169623 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit cda909c5e0b88fa3d12abe43fc72b8dd0729417a"
author bgruening
date Thu, 09 Apr 2020 10:08:32 -0400
parents 1dd562ae055d
children 50ca8845e7f5
comparison
equal deleted inserted replaced
10:1dd562ae055d 11:854a7a169623
38 def filter_precalculated_compounds(args, filters): 38 def filter_precalculated_compounds(args, filters):
39 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True) 39 outfile = pybel.Outputfile(args.oformat, args.output, overwrite=True)
40 for mol in pybel.readfile('sdf', args.input): 40 for mol in pybel.readfile('sdf', args.input):
41 for key, elem in filters.items(): 41 for key, elem in filters.items():
42 # map the short description to the larger metadata names stored in the sdf file 42 # map the short description to the larger metadata names stored in the sdf file
43 property = cheminfolib.ColumnNames[key] 43 property = cheminfolib.ColumnNames.get(key, key)
44 min = elem[0] 44 min = elem[0]
45 max = elem[1] 45 max = elem[1]
46 if float(mol.data[property]) >= float(min) and float(mol.data[property]) <= float(max): 46 if float(mol.data[property]) >= float(min) and float(mol.data[property]) <= float(max):
47 pass 47 pass
48 else: 48 else:
111 filters = json.loads((args.filters).replace(' ', '').replace(',}', '}')) 111 filters = json.loads((args.filters).replace(' ', '').replace(',}', '}'))
112 if args.iformat == 'sdf': 112 if args.iformat == 'sdf':
113 # Check if the sdf file contains all of the required metadata to invoke the precalculation filtering 113 # Check if the sdf file contains all of the required metadata to invoke the precalculation filtering
114 mol = next(pybel.readfile('sdf', args.input)) 114 mol = next(pybel.readfile('sdf', args.input))
115 for key, elem in filters.items(): 115 for key, elem in filters.items():
116 property = cheminfolib.ColumnNames[key] 116 property = cheminfolib.ColumnNames.get(key, key)
117 if not property in mol.data: 117 if not property in mol.data:
118 break 118 break
119 else: 119 else:
120 # if the for loop finishes in a normal way, we should habe all properties at least in the first molecule 120 # if the for loop finishes in a normal way, we should habe all properties at least in the first molecule
121 # assume it is the same for all other molecules and start the precalculated filtering 121 # assume it is the same for all other molecules and start the precalculated filtering