|
|
|
|
458
|
return saved_plots
|
458
|
return saved_plots
|
459
|
|
459
|
|
460
|
def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax = None, n_ticks = 10, subset = None, theta_scale = False):
|
460
|
def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax = None, n_ticks = 10, subset = None, theta_scale = False):
|
|
|
461
|
+ recent_limit_years = 500
|
|
|
462
|
+ # recent limit in coal. time
|
|
|
463
|
+ recent_limit = recent_limit_years/tgen*mu
|
461
|
# nb of plot_lines represent the number of epochs stored (len(plot_lines) = #breaks+1)
|
464
|
# nb of plot_lines represent the number of epochs stored (len(plot_lines) = #breaks+1)
|
462
|
nb_epochs = len(plot_lines)
|
465
|
nb_epochs = len(plot_lines)
|
463
|
# fig 2 & 3
|
466
|
# fig 2 & 3
|
|
|
|
|
487
|
# Plotting (fig 3) which is the same but log scale for x
|
490
|
# Plotting (fig 3) which is the same but log scale for x
|
488
|
p3, = ax3.plot(x2_plot, y2_plot, linestyle="-", alpha=0.75, lw=2, label = 'swp2', color="black")
|
491
|
p3, = ax3.plot(x2_plot, y2_plot, linestyle="-", alpha=0.75, lw=2, label = 'swp2', color="black")
|
489
|
lines_fig3.append(p3)
|
492
|
lines_fig3.append(p3)
|
490
|
- min_x = 0
|
|
|
491
|
- min_y = 0
|
|
|
|
|
493
|
+ min_x = 1
|
|
|
494
|
+ min_y = 1
|
492
|
max_x = 0
|
495
|
max_x = 0
|
493
|
max_y = 0
|
496
|
max_y = 0
|
494
|
for breaks, plot in enumerate(plot_lines):
|
497
|
for breaks, plot in enumerate(plot_lines):
|
|
|
|
|
502
|
min_y = min(min_y, min(y2_plot))
|
505
|
min_y = min(min_y, min(y2_plot))
|
503
|
max_x = max(max_x, max(x2_plot))
|
506
|
max_x = max(max_x, max(x2_plot))
|
504
|
max_y = max(max_y, max(y2_plot))
|
507
|
max_y = max(max_y, max(y2_plot))
|
|
|
508
|
+
|
|
|
509
|
+ # skip the base 0 points x_plot[0:3]
|
|
|
510
|
+ t_max_below_limit = 0
|
|
|
511
|
+ t_min_below_limit = 1
|
|
|
512
|
+ recent_change = False
|
|
|
513
|
+ for t in x[1:]:
|
|
|
514
|
+ if t <= recent_limit:
|
|
|
515
|
+ recent_change = True
|
|
|
516
|
+ t_max_below_limit = max(t_max_below_limit, t)
|
|
|
517
|
+ t_min_below_limit = min(t_min_below_limit, t)
|
|
|
518
|
+ Ne_max_below_limit = y[x.index(t_max_below_limit)]
|
|
|
519
|
+ Ne_min_below_limit = y[x.index(t_min_below_limit)]
|
|
|
520
|
+ if recent_change:
|
|
|
521
|
+ print(f"\n{breaks} breaks ; This is below the recent limit of {recent_limit_years} years:\n",
|
|
|
522
|
+ f"t_min (most recent time point under the limit) : {t_min_below_limit/mu*tgen:.1f} t_max (most ancient time point under the limit) : {t_max_below_limit/mu*tgen:.1f}",
|
|
|
523
|
+ f"\nNe_min (effective size at t_min) : {Ne_min_below_limit/(4*mu):.1f} Ne_max (effective size at t_max) : {Ne_max_below_limit/(4*mu):.1f}",
|
|
|
524
|
+ f"\nNe_min/Ne_max = {(Ne_min_below_limit/(4*mu)) / (Ne_max_below_limit/(4*mu)):.1f}",
|
|
|
525
|
+ f"\nEvolution: {((Ne_min_below_limit/(4*mu)) - (Ne_max_below_limit/(4*mu)))/((Ne_max_below_limit/(4*mu)))*100:.1f}%")
|
|
|
526
|
+ else:
|
|
|
527
|
+ print(f"Recent event under {recent_limit_years} years: NA")
|
|
|
528
|
+ # need to compute the last change and when it occured
|
|
|
529
|
+ tmin = x[1]
|
|
|
530
|
+ tmin_plus_1 = x[2]
|
|
|
531
|
+ Ne_min = y[1]
|
|
|
532
|
+ Ne_min_plus_1 = y[2]
|
|
|
533
|
+ print(f"Last was {tmin/mu*tgen:.1f} years ago. And was of {((Ne_min/(4*mu)) - (Ne_min_plus_1/(4*mu)))/(Ne_min_plus_1/(4*mu))*100:.1f}%")
|
|
|
534
|
+
|
505
|
else:
|
535
|
else:
|
506
|
masking_alpha = 0
|
536
|
masking_alpha = 0
|
507
|
autoscale = False
|
537
|
autoscale = False
|
508
|
ax2.set_autoscale_on(autoscale)
|
538
|
ax2.set_autoscale_on(autoscale)
|
509
|
ax3.set_autoscale_on(autoscale)
|
539
|
ax3.set_autoscale_on(autoscale)
|
|
|
540
|
+
|
510
|
p2, = ax2.plot(x2_plot, y2_plot, 'o', linestyle="-", alpha=masking_alpha, lw=2, label = str(breaks)+' brks')
|
541
|
p2, = ax2.plot(x2_plot, y2_plot, 'o', linestyle="-", alpha=masking_alpha, lw=2, label = str(breaks)+' brks')
|
511
|
# Plotting (fig 3) which is the same but log scale for x
|
542
|
# Plotting (fig 3) which is the same but log scale for x
|
512
|
p3, = ax3.plot(x2_plot, y2_plot, 'o', linestyle="-", alpha=masking_alpha, lw=2, label = str(breaks)+' brks')
|
543
|
p3, = ax3.plot(x2_plot, y2_plot, 'o', linestyle="-", alpha=masking_alpha, lw=2, label = str(breaks)+' brks')
|
|
|
|
|
514
|
# store for legend
|
545
|
# store for legend
|
515
|
lines_fig2.append(p2)
|
546
|
lines_fig2.append(p2)
|
516
|
lines_fig3.append(p3)
|
547
|
lines_fig3.append(p3)
|
517
|
- ax3.axvline(x=500/tgen*mu, linestyle="--")
|
|
|
|
|
548
|
+ # put the vertical line of the "recent" time limit
|
|
|
549
|
+ ax3.axvline(x=recent_limit, linestyle="--")
|
518
|
if theta_scale:
|
550
|
if theta_scale:
|
519
|
xlabel = "Theta scaled by N0"
|
551
|
xlabel = "Theta scaled by N0"
|
520
|
ylabel = "Theta scaled by N0"
|
552
|
ylabel = "Theta scaled by N0"
|
|
|
|
|
527
|
plt.ylabel(ylabel, fontsize=fnt_size)
|
559
|
plt.ylabel(ylabel, fontsize=fnt_size)
|
528
|
#plt.xlim(left=0)
|
560
|
#plt.xlim(left=0)
|
529
|
#xlim_val = plt.gca().get_xlim()
|
561
|
#xlim_val = plt.gca().get_xlim()
|
530
|
- x_ticks = list(plt.xticks())[0]
|
|
|
531
|
- # plt.gca().set_xticks(x_ticks)
|
|
|
532
|
- plt.xticks(x_ticks)
|
|
|
533
|
- # plt.gca().set_xlim(xlim_val)
|
|
|
|
|
562
|
+ #x_ticks = list(plt.xticks())[0]
|
534
|
plt.xlim(min(min_x,min(swp2_lines[0])), max(max(swp2_lines[0]), max_x))
|
563
|
plt.xlim(min(min_x,min(swp2_lines[0])), max(max(swp2_lines[0]), max_x))
|
|
|
564
|
+ x_ticks = list(plt.gca().get_xticks())
|
|
|
565
|
+ plt.gca().set_xticks(x_ticks)
|
|
|
566
|
+ # plt.xticks(x_ticks)
|
|
|
567
|
+ # plt.gca().set_xlim(xlim_val)
|
535
|
plt.gca().set_xticklabels([f'{k:.0e}\n{k/(mu):.0e}\n{k/(mu)*tgen:.0e}' for k in x_ticks], fontsize = fnt_size*0.5)
|
568
|
plt.gca().set_xticklabels([f'{k:.0e}\n{k/(mu):.0e}\n{k/(mu)*tgen:.0e}' for k in x_ticks], fontsize = fnt_size*0.5)
|
536
|
# rescale y to effective pop size
|
569
|
# rescale y to effective pop size
|
537
|
# ylim_val = plt.gca().get_ylim()
|
570
|
# ylim_val = plt.gca().get_ylim()
|
|
|
571
|
+ plt.ylim(min(min_y,min(swp2_lines[1])), max(max_y+(max_y*0.05), max(swp2_lines[1])+(max(swp2_lines[1])*0.05)))
|
538
|
y_ticks = list(plt.yticks())[0]
|
572
|
y_ticks = list(plt.yticks())[0]
|
539
|
- # plt.gca().set_yticks(y_ticks)
|
|
|
|
|
573
|
+ plt.gca().set_yticks(y_ticks)
|
540
|
# plt.gca().set_ylim(ylim_val)
|
574
|
# plt.gca().set_ylim(ylim_val)
|
541
|
plt.yticks(y_ticks)
|
575
|
plt.yticks(y_ticks)
|
542
|
- plt.ylim(min(min_y,min(swp2_lines[1])), max(max_y+(max_y*0.05), max(swp2_lines[1])+(max(swp2_lines[1])*0.05)))
|
|
|
543
|
plt.gca().set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
|
576
|
plt.gca().set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
|
544
|
plt.title(title, fontsize=fnt_size)
|
577
|
plt.title(title, fontsize=fnt_size)
|
545
|
plt.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5)
|
578
|
plt.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5)
|