浏览代码

Fixing the sorting of best scenarios for swp2 parsing

tforest 9 个月前
父节点
当前提交
541d1d7348
共有 1 个文件被更改,包括 12 次插入3 次删除
  1. 12 3
      swp2.py

+ 12 - 3
swp2.py 查看文件

@@ -252,6 +252,7 @@ def save_all_epochs_thetafolder(folder_path, mu, tgen, title = "Title", theta_sc
252 252
     print(cpt, "theta file(s) have been scanned.")
253 253
     brkpt_lik = []
254 254
     top_plots = {}
255
+    best_scenario_for_epoch = {}
255 256
     for epoch, scenari in epochs.items():
256 257
         # sort starting by the smallest -log(Likelihood)
257 258
         best10_scenari = (sorted(list(scenari.keys())))[:10]
@@ -270,6 +271,7 @@ def save_all_epochs_thetafolder(folder_path, mu, tgen, title = "Title", theta_sc
270 271
                 y[i] = y[i]/N0
271 272
                 x[i] = x[i]/N0
272 273
         top_plots[greatest_likelihood] = x,y,epoch
274
+        best_scenario_for_epoch[epoch] = x,y,greatest_likelihood
273 275
     plots_likelihoods = list(top_plots.keys())
274 276
     for i in range(len(plots_likelihoods)):
275 277
         plots_likelihoods[i] = float(plots_likelihoods[i])
@@ -278,9 +280,16 @@ def save_all_epochs_thetafolder(folder_path, mu, tgen, title = "Title", theta_sc
278 280
     # store x,y,brks,likelihood
279 281
     plots['best'] = (top_plots[top_plot_lik][0], top_plots[top_plot_lik][1], str(top_plots[top_plot_lik][2]), top_plot_lik)
280 282
     plots['plots'] = []
281
-    for k, plot_Lk in enumerate(best10_plots[1:]):
282
-        plot_Lk = str(plot_Lk)
283
-        plots['plots'].append([top_plots[plot_Lk][0], top_plots[plot_Lk][1], str(top_plots[plot_Lk][2]), plot_Lk])
283
+    for k, epoch in enumerate(best_scenario_for_epoch.keys()):
284
+        plot_Lk = str(best_scenario_for_epoch[epoch][2])
285
+        x,y = best_scenario_for_epoch[epoch][0], best_scenario_for_epoch[epoch][1]
286
+        plots['plots'].append([x, y, str(epoch), plot_Lk])
287
+    plots['plots'] = sorted(plots['plots'], key=lambda x: float(x[3]))
288
+    plots['plots'] = plots['plots'][1:]
289
+    # Previous version. Was this correct????
290
+    # for k, plot_Lk in enumerate(best10_plots[1:]):
291
+    #     plot_Lk = str(plot_Lk)
292
+    #     plots['plots'].append([top_plots[plot_Lk][0], top_plots[plot_Lk][1], str(top_plots[plot_Lk][2]), plot_Lk])
284 293
     # plot likelihood against nb of breakpoints
285 294
     # best possible likelihood from SFS
286 295
     # Segregating sites