Skip to content

Instantly share code, notes, and snippets.

@jamessdixon
Created May 30, 2023 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamessdixon/77b5fcddfe2c204790a2875ea57a2120 to your computer and use it in GitHub Desktop.
Save jamessdixon/77b5fcddfe2c204790a2875ea57a2120 to your computer and use it in GitHub Desktop.
Using Higher Order Functions In Hypedsearch
#original
def do_fourth_thing(spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol):
start_time = time.time()
hybrid_merged = clustering.get_hybrid_matches(b_sorted_clusters, y_sorted_clusters, spectrum.precursor_mass, prec_tol, spectrum.precursor_charge)
end_time = time.time() - start_time
with open('Timing_data.txt', 'a') as t:
t.write("Finding hybrid merges took:" + '\t' + str(end_time) + "\n")
return hybrid_merged
#reduces to
def do_fourth_thing(spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol):
hybrid_merged = clustering.get_hybrid_matches(b_sorted_clusters, y_sorted_clusters, spectrum.precursor_mass, prec_tol, spectrum.precursor_charge)
def write_metrics(func, spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol):
start_time = time.time()
func(spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol)
end_time = time.time() - start_time
with open('Timing_data.txt', 'a') as t:
t.write("Finding hybrid merges took:" + '\t' + str(end_time) + "\n")
return hybrid_merged
write_metrics(do_fourth_thing,spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol)
#reduces to
def write_metrics(func, spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol):
start_time = time.time()
func(spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol)
end_time = time.time() - start_time
with open('Timing_data.txt', 'a') as t:
t.write("Finding hybrid merges took:" + '\t' + str(end_time) + "\n")
return hybrid_merged
write_metrics(clustering.get_hybrid_matches,spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment