Previous changeset 1:334ad24525db (2019-10-11) Next changeset 3:bd12f4b4c3a8 (2020-03-28) |
Commit message:
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d" |
modified:
sucos.py sucos_max.py |
b |
diff -r 334ad24525db -r 58d18838e244 sucos.py --- a/sucos.py Fri Oct 11 18:26:08 2019 -0400 +++ b/sucos.py Thu Mar 19 07:25:25 2020 -0400 |
b |
@@ -109,17 +109,21 @@ fm_score = get_FeatureMapScore(ref_features, query_features, tani, score_mode) fm_score = np.clip(fm_score, 0, 1) - if tani: - tani_sim = 1 - float(rdShapeHelpers.ShapeTanimotoDist(ref_mol, query_mol)) - tani_sim = np.clip(tani_sim, 0, 1) - SuCOS_score = 0.5*fm_score + 0.5*tani_sim - return SuCOS_score, fm_score, tani_sim - else: - protrude_dist = rdShapeHelpers.ShapeProtrudeDist(ref_mol, query_mol, allowReordering=False) - protrude_dist = np.clip(protrude_dist, 0, 1) - protrude_val = 1.0 - protrude_dist - SuCOS_score = 0.5 * fm_score + 0.5 * protrude_val - return SuCOS_score, fm_score, protrude_val + try : + if tani: + tani_sim = 1 - float(rdShapeHelpers.ShapeTanimotoDist(ref_mol, query_mol)) + tani_sim = np.clip(tani_sim, 0, 1) + SuCOS_score = 0.5*fm_score + 0.5*tani_sim + return SuCOS_score, fm_score, tani_sim + else: + protrude_dist = rdShapeHelpers.ShapeProtrudeDist(ref_mol, query_mol, allowReordering=False) + protrude_dist = np.clip(protrude_dist, 0, 1) + protrude_val = 1.0 - protrude_dist + SuCOS_score = 0.5 * fm_score + 0.5 * protrude_val + return SuCOS_score, fm_score, protrude_val + except: + utils.log("Failed to calculate SuCOS scores. Returning 0,0,0") + return 0, 0, 0 def process(refmol_filename, inputs_filename, outputs_filename, refmol_index=None, refmol_format=None, tani=False, score_mode=FeatMaps.FeatMapScoreMode.All): |
b |
diff -r 334ad24525db -r 58d18838e244 sucos_max.py --- a/sucos_max.py Fri Oct 11 18:26:08 2019 -0400 +++ b/sucos_max.py Thu Mar 19 07:25:25 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() |