Fixing the sorting of best scenarios for swp2 parsing

master
tforest 2024-02-25 03:53:32 +01:00
parent 0ffb02e511
commit 541d1d7348
1 changed files with 12 additions and 3 deletions

15
swp2.py
View File

@ -252,6 +252,7 @@ def save_all_epochs_thetafolder(folder_path, mu, tgen, title = "Title", theta_sc
print(cpt, "theta file(s) have been scanned.") print(cpt, "theta file(s) have been scanned.")
brkpt_lik = [] brkpt_lik = []
top_plots = {} top_plots = {}
best_scenario_for_epoch = {}
for epoch, scenari in epochs.items(): for epoch, scenari in epochs.items():
# sort starting by the smallest -log(Likelihood) # sort starting by the smallest -log(Likelihood)
best10_scenari = (sorted(list(scenari.keys())))[:10] best10_scenari = (sorted(list(scenari.keys())))[:10]
@ -270,6 +271,7 @@ def save_all_epochs_thetafolder(folder_path, mu, tgen, title = "Title", theta_sc
y[i] = y[i]/N0 y[i] = y[i]/N0
x[i] = x[i]/N0 x[i] = x[i]/N0
top_plots[greatest_likelihood] = x,y,epoch top_plots[greatest_likelihood] = x,y,epoch
best_scenario_for_epoch[epoch] = x,y,greatest_likelihood
plots_likelihoods = list(top_plots.keys()) plots_likelihoods = list(top_plots.keys())
for i in range(len(plots_likelihoods)): for i in range(len(plots_likelihoods)):
plots_likelihoods[i] = float(plots_likelihoods[i]) plots_likelihoods[i] = float(plots_likelihoods[i])
@ -278,9 +280,16 @@ def save_all_epochs_thetafolder(folder_path, mu, tgen, title = "Title", theta_sc
# store x,y,brks,likelihood # store x,y,brks,likelihood
plots['best'] = (top_plots[top_plot_lik][0], top_plots[top_plot_lik][1], str(top_plots[top_plot_lik][2]), top_plot_lik) plots['best'] = (top_plots[top_plot_lik][0], top_plots[top_plot_lik][1], str(top_plots[top_plot_lik][2]), top_plot_lik)
plots['plots'] = [] plots['plots'] = []
for k, plot_Lk in enumerate(best10_plots[1:]): for k, epoch in enumerate(best_scenario_for_epoch.keys()):
plot_Lk = str(plot_Lk) plot_Lk = str(best_scenario_for_epoch[epoch][2])
plots['plots'].append([top_plots[plot_Lk][0], top_plots[plot_Lk][1], str(top_plots[plot_Lk][2]), plot_Lk]) x,y = best_scenario_for_epoch[epoch][0], best_scenario_for_epoch[epoch][1]
plots['plots'].append([x, y, str(epoch), plot_Lk])
plots['plots'] = sorted(plots['plots'], key=lambda x: float(x[3]))
plots['plots'] = plots['plots'][1:]
# Previous version. Was this correct????
# for k, plot_Lk in enumerate(best10_plots[1:]):
# plot_Lk = str(plot_Lk)
# plots['plots'].append([top_plots[plot_Lk][0], top_plots[plot_Lk][1], str(top_plots[plot_Lk][2]), plot_Lk])
# plot likelihood against nb of breakpoints # plot likelihood against nb of breakpoints
# best possible likelihood from SFS # best possible likelihood from SFS
# Segregating sites # Segregating sites