Mercurial > repos > bgruening > openbabel_svg_depiction
diff ob_spectrophore_search.py @ 13:a66827fc370d draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/openbabel commit 1fe240ef0064a1a4a66d9be1ccace53824280b75"
author | bgruening |
---|---|
date | Mon, 19 Oct 2020 14:45:37 +0000 |
parents | d3b48303045b |
children | 75ee9c410951 |
line wrap: on
line diff
--- a/ob_spectrophore_search.py Tue Jul 28 08:35:16 2020 -0400 +++ b/ob_spectrophore_search.py Mon Oct 19 14:45:37 2020 +0000 @@ -4,18 +4,17 @@ Output: parse the target file using the same protocol used to generate the databases in our servers. Physico-chemical properties are computed and stored as metadata in the sdf output file. Copyright 2012, Bjoern Gruening and Xavier Lucas """ -import sys, os import argparse -import math + import numpy as np - from openbabel import openbabel, pybel openbabel.obErrorLog.StopLogging() -#TODO get rid of eval() +# TODO get rid of eval() global spectrophore spectrophore = pybel.ob.OBSpectrophore() + def parse_command_line(): parser = argparse.ArgumentParser() parser.add_argument('--target', required=True, help='target file name in sdf format with Spectrophores(TM) descriptors stored as meta-data') @@ -28,26 +27,29 @@ parser.add_argument('-r', '--resolution', type=float, default="3.0", help='Resolution') return parser.parse_args() + def set_parameters(args): if args.normalization == 'No': - spectrophore.SetNormalization( spectrophore.NoNormalization ) + spectrophore.SetNormalization(spectrophore.NoNormalization) else: - spectrophore.SetNormalization( eval('spectrophore.NormalizationTowards' + args.normalization) ) - spectrophore.SetAccuracy( eval('spectrophore.AngStepSize' + args.accuracy) ) - spectrophore.SetStereo( eval('spectrophore.' + args.stereo + 'StereoSpecificProbes') ) - spectrophore.SetResolution( args.resolution ) + spectrophore.SetNormalization(eval('spectrophore.NormalizationTowards' + args.normalization)) + spectrophore.SetAccuracy(eval('spectrophore.AngStepSize' + args.accuracy)) + spectrophore.SetStereo(eval('spectrophore.' + args.stereo + 'StereoSpecificProbes')) + spectrophore.SetResolution(args.resolution) return True + def Compute_Spectrophores_distance(target_spectrophore, args): outfile = open(args.output, 'w') for mol in open(args.library, 'r'): try: - distance = ( ( np.asarray( target_spectrophore, dtype=float ) - np.asarray( mol.split('\t')[ args.column - 1 ].strip().split(', '), dtype=float) )**2).sum() + distance = ((np.asarray(target_spectrophore, dtype=float) - np.asarray(mol.split('\t')[args.column - 1].strip().split(', '), dtype=float))**2).sum() except ValueError: distance = 0 - outfile.write( '%s\t%f\n' % (mol.strip(), distance ) ) + outfile.write('%s\t%f\n' % (mol.strip(), distance)) outfile.close() + def __main__(): """ Computation of Spectrophores(TM) distances to a target molecule. @@ -59,7 +61,8 @@ mol = next(pybel.readfile('sdf', args.target)) target_spectrophore = mol.data["Spectrophores(TM)"].strip().split(', ') # Compute the paired-distance between every molecule in the library and the target - distances = Compute_Spectrophores_distance(target_spectrophore, args) + Compute_Spectrophores_distance(target_spectrophore, args) + -if __name__ == "__main__" : +if __name__ == "__main__": __main__()