Add some outputs for swp2 parsing
parent
7949befb40
commit
14538a747b
51
swp2.py
51
swp2.py
|
|
@ -458,6 +458,9 @@ def save_k_theta(folder_path, mu, tgen, title = "Title", theta_scale = True,
|
|||
return saved_plots
|
||||
|
||||
def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax = None, n_ticks = 10, subset = None, theta_scale = False):
|
||||
recent_limit_years = 500
|
||||
# recent limit in coal. time
|
||||
recent_limit = recent_limit_years/tgen*mu
|
||||
# nb of plot_lines represent the number of epochs stored (len(plot_lines) = #breaks+1)
|
||||
nb_epochs = len(plot_lines)
|
||||
# fig 2 & 3
|
||||
|
|
@ -487,8 +490,8 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
|
|||
# Plotting (fig 3) which is the same but log scale for x
|
||||
p3, = ax3.plot(x2_plot, y2_plot, linestyle="-", alpha=0.75, lw=2, label = 'swp2', color="black")
|
||||
lines_fig3.append(p3)
|
||||
min_x = 0
|
||||
min_y = 0
|
||||
min_x = 1
|
||||
min_y = 1
|
||||
max_x = 0
|
||||
max_y = 0
|
||||
for breaks, plot in enumerate(plot_lines):
|
||||
|
|
@ -502,11 +505,39 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
|
|||
min_y = min(min_y, min(y2_plot))
|
||||
max_x = max(max_x, max(x2_plot))
|
||||
max_y = max(max_y, max(y2_plot))
|
||||
|
||||
# skip the base 0 points x_plot[0:3]
|
||||
t_max_below_limit = 0
|
||||
t_min_below_limit = 1
|
||||
recent_change = False
|
||||
for t in x[1:]:
|
||||
if t <= recent_limit:
|
||||
recent_change = True
|
||||
t_max_below_limit = max(t_max_below_limit, t)
|
||||
t_min_below_limit = min(t_min_below_limit, t)
|
||||
Ne_max_below_limit = y[x.index(t_max_below_limit)]
|
||||
Ne_min_below_limit = y[x.index(t_min_below_limit)]
|
||||
if recent_change:
|
||||
print(f"\n{breaks} breaks ; This is below the recent limit of {recent_limit_years} years:\n",
|
||||
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}",
|
||||
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}",
|
||||
f"\nNe_min/Ne_max = {(Ne_min_below_limit/(4*mu)) / (Ne_max_below_limit/(4*mu)):.1f}",
|
||||
f"\nEvolution: {((Ne_min_below_limit/(4*mu)) - (Ne_max_below_limit/(4*mu)))/((Ne_max_below_limit/(4*mu)))*100:.1f}%")
|
||||
else:
|
||||
print(f"Recent event under {recent_limit_years} years: NA")
|
||||
# need to compute the last change and when it occured
|
||||
tmin = x[1]
|
||||
tmin_plus_1 = x[2]
|
||||
Ne_min = y[1]
|
||||
Ne_min_plus_1 = y[2]
|
||||
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}%")
|
||||
|
||||
else:
|
||||
masking_alpha = 0
|
||||
autoscale = False
|
||||
ax2.set_autoscale_on(autoscale)
|
||||
ax3.set_autoscale_on(autoscale)
|
||||
|
||||
p2, = ax2.plot(x2_plot, y2_plot, 'o', linestyle="-", alpha=masking_alpha, lw=2, label = str(breaks)+' brks')
|
||||
# Plotting (fig 3) which is the same but log scale for x
|
||||
p3, = ax3.plot(x2_plot, y2_plot, 'o', linestyle="-", alpha=masking_alpha, lw=2, label = str(breaks)+' brks')
|
||||
|
|
@ -514,7 +545,8 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
|
|||
# store for legend
|
||||
lines_fig2.append(p2)
|
||||
lines_fig3.append(p3)
|
||||
ax3.axvline(x=500/tgen*mu, linestyle="--")
|
||||
# put the vertical line of the "recent" time limit
|
||||
ax3.axvline(x=recent_limit, linestyle="--")
|
||||
if theta_scale:
|
||||
xlabel = "Theta scaled by N0"
|
||||
ylabel = "Theta scaled by N0"
|
||||
|
|
@ -527,19 +559,20 @@ def plot_scaled_theta(plot_lines, prop, title, mu, tgen, swp2_lines = None, ax =
|
|||
plt.ylabel(ylabel, fontsize=fnt_size)
|
||||
#plt.xlim(left=0)
|
||||
#xlim_val = plt.gca().get_xlim()
|
||||
x_ticks = list(plt.xticks())[0]
|
||||
# plt.gca().set_xticks(x_ticks)
|
||||
plt.xticks(x_ticks)
|
||||
# plt.gca().set_xlim(xlim_val)
|
||||
#x_ticks = list(plt.xticks())[0]
|
||||
plt.xlim(min(min_x,min(swp2_lines[0])), max(max(swp2_lines[0]), max_x))
|
||||
x_ticks = list(plt.gca().get_xticks())
|
||||
plt.gca().set_xticks(x_ticks)
|
||||
# plt.xticks(x_ticks)
|
||||
# plt.gca().set_xlim(xlim_val)
|
||||
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)
|
||||
# rescale y to effective pop size
|
||||
# ylim_val = plt.gca().get_ylim()
|
||||
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)))
|
||||
y_ticks = list(plt.yticks())[0]
|
||||
# plt.gca().set_yticks(y_ticks)
|
||||
plt.gca().set_yticks(y_ticks)
|
||||
# plt.gca().set_ylim(ylim_val)
|
||||
plt.yticks(y_ticks)
|
||||
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)))
|
||||
plt.gca().set_yticklabels([f'{k/(4*mu):.0e}' for k in y_ticks], fontsize = fnt_size*0.5)
|
||||
plt.title(title, fontsize=fnt_size)
|
||||
plt.legend(handles=lines_fig2, loc='best', fontsize = fnt_size*0.5)
|
||||
|
|
|
|||
Loading…
Reference in New Issue