diff --git a/swp2.py b/swp2.py index 207021c..69e6a24 100644 --- a/swp2.py +++ b/swp2.py @@ -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.") brkpt_lik = [] top_plots = {} + best_scenario_for_epoch = {} for epoch, scenari in epochs.items(): # sort starting by the smallest -log(Likelihood) 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 x[i] = x[i]/N0 top_plots[greatest_likelihood] = x,y,epoch + best_scenario_for_epoch[epoch] = x,y,greatest_likelihood plots_likelihoods = list(top_plots.keys()) for i in range(len(plots_likelihoods)): 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 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'] = [] - 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]) + for k, epoch in enumerate(best_scenario_for_epoch.keys()): + plot_Lk = str(best_scenario_for_epoch[epoch][2]) + 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 # best possible likelihood from SFS # Segregating sites