Mercurial > repos > bgruening > sucos_max_score
diff sucos_max.py @ 2:2f110aef9b53 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
author | bgruening |
---|---|
date | Thu, 19 Mar 2020 09:43:31 -0400 |
parents | bb5365381c8f |
children | bf99565cec1f |
line wrap: on
line diff
--- a/sucos_max.py Fri Oct 11 18:25:27 2019 -0400 +++ b/sucos_max.py Thu Mar 19 09:43:31 2020 -0400 @@ -39,8 +39,7 @@ from rdkit import Chem -def process(inputfilename, clusterfilenames, outputfilename, mode): - +def process(inputfilename, clusterfilenames, outputfilename): all_clusters = {} for filename in clusterfilenames: cluster = [] @@ -79,7 +78,8 @@ except: utils.log("WARNING: failed to generate features for molecule", mol_num, "in input") continue - scores = [0, 0, 0] + scores_max = [0, 0, 0] + scores_cum = [0, 0, 0] for clusterfilename in all_clusters: cluster = all_clusters[clusterfilename] index = 0 @@ -89,42 +89,35 @@ index += 1 comparisons += 1 sucos_score, fm_score, vol_score = sucos.get_SucosScore(hit, mol, - tani=False, ref_features=ref_features, query_features=query_features) - if mode == 'max': - if sucos_score > scores[0]: - scores[0] = sucos_score - scores[1] = fm_score - scores[2] = vol_score - cluster_name = clusterfilename - cluster_index = index - elif mode == 'cum': - scores[0] += sucos_score - scores[1] += fm_score - scores[2] += vol_score - else: - raise ValueError("Invalid mode: " + mode) + tani=False, ref_features=ref_features, + query_features=query_features) + + if sucos_score > scores_max[0]: + scores_max[0] = sucos_score + scores_max[1] = fm_score + scores_max[2] = vol_score + cluster_name = clusterfilename + cluster_index = index + + scores_cum[0] += sucos_score + scores_cum[1] += fm_score + scores_cum[2] += vol_score - if scores[0] > 0: - if mode == 'max': - cluster_file_name_only = cluster_name.split(os.sep)[-1] - #utils.log("Max SuCOS:", scores[0], "FM:", scores[1], "P:", scores[2],"File:", cluster_file_name_only, "Index:", cluster_index) - mol.SetDoubleProp("Max_SuCOS_Score", scores[0]) - mol.SetDoubleProp("Max_SuCOS_FeatureMap_Score", scores[1]) - mol.SetDoubleProp("Max_SuCOS_Protrude_Score", scores[2]) - mol.SetProp("Max_SuCOS_Cluster", cluster_file_name_only) - mol.SetIntProp("Max_SuCOS_Index", cluster_index) + if scores_max[0] > 0: + cluster_file_name_only = cluster_name.split(os.sep)[-1] + # utils.log("Max SuCOS:", scores[0], "FM:", scores[1], "P:", scores[2],"File:", cluster_file_name_only, "Index:", cluster_index) + mol.SetDoubleProp("Max_SuCOS_Score", scores_max[0]) + mol.SetDoubleProp("Max_SuCOS_FeatureMap_Score", scores_max[1]) + mol.SetDoubleProp("Max_SuCOS_Protrude_Score", scores_max[2]) + mol.SetProp("Max_SuCOS_Cluster", cluster_file_name_only) + mol.SetIntProp("Max_SuCOS_Index", cluster_index) - else: - #utils.log("Cum SuCOS:", scores[0], "FM:", scores[1], "P:", scores[2]) - mol.SetDoubleProp("Cum_SuCOS_Score", scores[0]) - mol.SetDoubleProp("Cum_SuCOS_FeatureMap_Score", scores[1]) - mol.SetDoubleProp("Cum_SuCOS_Protrude_Score", scores[2]) + # utils.log("Cum SuCOS:", scores[0], "FM:", scores[1], "P:", scores[2]) + mol.SetDoubleProp("Cum_SuCOS_Score", scores_cum[0]) + mol.SetDoubleProp("Cum_SuCOS_FeatureMap_Score", scores_cum[1]) + mol.SetDoubleProp("Cum_SuCOS_Protrude_Score", scores_cum[2]) - writer.write(mol) - - else: - utils.log("Molecule", mol_num, "did not overlay. Omitting from results") - + writer.write(mol) input_file.close() writer.flush() @@ -140,15 +133,13 @@ parser = argparse.ArgumentParser(description='Max SuCOS scores with RDKit') parser.add_argument('-i', '--input', help='Input file to score in SDF format. Can be gzipped (*.gz).') parser.add_argument('-o', '--output', help='Output file in SDF format. Can be gzipped (*.gz).') - parser.add_argument('-m', '--mode', choices=['max', 'cum'], - default='max', help='Score mode: max = best score, cum = sum of all scores') parser.add_argument('clusters', nargs='*', help="One or more SDF files with the clustered hits") args = parser.parse_args() utils.log("Max SuCOS Args: ", args) - process(args.input, args.clusters, args.output, args.mode) + process(args.input, args.clusters, args.output) if __name__ == "__main__": - main() \ No newline at end of file + main()