comparison sucos_max.py @ 5:d4c67ced6abc draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit c35334ca80c87a5078da1a6df85b34e23b80d837"
author bgruening
date Wed, 15 Apr 2020 09:26:07 -0400
parents 85fad59f8168
children 9b48456a96fe
comparison
equal deleted inserted replaced
4:85fad59f8168 5:d4c67ced6abc
37 import sucos, utils 37 import sucos, utils
38 import argparse, gzip, os 38 import argparse, gzip, os
39 from rdkit import Chem 39 from rdkit import Chem
40 40
41 41
42 def process(inputfilename, clusterfilenames, outputfilename): 42 def process(inputfilename, clusterfilenames, outputfilename, filter_value, filter_field):
43 all_clusters = {} 43 all_clusters = {}
44 for filename in clusterfilenames: 44 for filename in clusterfilenames:
45 cluster = [] 45 cluster = []
46 cluster_file = utils.open_file_for_reading(filename) 46 cluster_file = utils.open_file_for_reading(filename)
47 suppl = Chem.ForwardSDMolSupplier(cluster_file) 47 suppl = Chem.ForwardSDMolSupplier(cluster_file)
118 # utils.log("Cum SuCOS:", scores[0], "FM:", scores[1], "P:", scores[2]) 118 # utils.log("Cum SuCOS:", scores[0], "FM:", scores[1], "P:", scores[2])
119 mol.SetDoubleProp("Cum_SuCOS_Score", scores_cum[0] if scores_cum[0] > 0 else 0) 119 mol.SetDoubleProp("Cum_SuCOS_Score", scores_cum[0] if scores_cum[0] > 0 else 0)
120 mol.SetDoubleProp("Cum_SuCOS_FeatureMap_Score", scores_cum[1] if scores_cum[1] > 0 else 0) 120 mol.SetDoubleProp("Cum_SuCOS_FeatureMap_Score", scores_cum[1] if scores_cum[1] > 0 else 0)
121 mol.SetDoubleProp("Cum_SuCOS_Protrude_Score", scores_cum[2] if scores_cum[2] > 0 else 0) 121 mol.SetDoubleProp("Cum_SuCOS_Protrude_Score", scores_cum[2] if scores_cum[2] > 0 else 0)
122 122
123 writer.write(mol) 123 if filter_value and filter_field:
124 if mol.HasProp(filter_field):
125 val = mol.GetDoubleProp(filter_field)
126 if val > filter_value:
127 writer.write(mol)
128 else:
129 writer.write(mol)
124 130
125 input_file.close() 131 input_file.close()
126 writer.flush() 132 writer.flush()
127 writer.close() 133 writer.close()
128 output_file.close() 134 output_file.close()
135 def main(): 141 def main():
136 parser = argparse.ArgumentParser(description='Max SuCOS scores with RDKit') 142 parser = argparse.ArgumentParser(description='Max SuCOS scores with RDKit')
137 parser.add_argument('-i', '--input', help='Input file to score in SDF format. Can be gzipped (*.gz).') 143 parser.add_argument('-i', '--input', help='Input file to score in SDF format. Can be gzipped (*.gz).')
138 parser.add_argument('-o', '--output', help='Output file in SDF format. Can be gzipped (*.gz).') 144 parser.add_argument('-o', '--output', help='Output file in SDF format. Can be gzipped (*.gz).')
139 parser.add_argument('clusters', nargs='*', help="One or more SDF files with the clustered hits") 145 parser.add_argument('clusters', nargs='*', help="One or more SDF files with the clustered hits")
146 parser.add_argument('--filter-value', type=float, help='Filter out values with scores less than this.')
147 parser.add_argument('--filter-field', help='Field to use to filter values.')
140 148
141 args = parser.parse_args() 149 args = parser.parse_args()
142 utils.log("Max SuCOS Args: ", args) 150 utils.log("Max SuCOS Args: ", args)
143 151
144 process(args.input, args.clusters, args.output) 152 process(args.input, args.clusters, args.output, args.filter_value, args.filter_field)
145 153
146 154
147 if __name__ == "__main__": 155 if __name__ == "__main__":
148 main() 156 main()