def get_r_scaled(x, scale="log2"):
x = np.asarray(x, dtype=float)
powers = np.arange(np.ceil(np.log2(x.min())), np.floor(np.log2(x.max())) + 1)
xlabels = 2 ** powers
if scale == "log10":
xscale = np.log10(x)
xticks = np.log10(xlabels)
elif scale == "log2":
xscale = np.log2(x)
xticks = np.log2(xlabels)
else:
xscale = x
xticks = xlabels
xlabel_str = [f"{r:g}" for r in xlabels]
return xscale, xticks, xlabel_str
plot_variants = {
'identity': {
'label': "Isotropic",
'tag_locs': [256, 512, 8192],
'tag_dx': -0.012,
'tag_dy': 0.0,
'tag_ha': "right",
},
'intercepts': {
'label': "LDSC Intercepts (Full)",
'tag_locs': [512, 2580, 6502],
'tag_dx': 0.012,
'tag_dy': 0.0,
'tag_ha': "left",
},
'shielded': {
'label': "LDSC Intercepts (Shielded)",
'tag_locs': [512],
'tag_dx': -0.012,
'tag_dy': 0.0,
'tag_ha': "right",
},
}
fig = plt.figure(figsize = (20,8))
gs = fig.add_gridspec(nrows=1, ncols=2, wspace=0.2, hspace=0)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
xcolname = "partial_noise_given_rg"
ycolname = "partial_rg_given_noise"
# xcolname = "spearman_vs_noise"
# ycolname = "spearman_vs_rg"
lines = {}
for vname, vparams in plot_variants.items():
df = recovery_df[vname]
lines[vname], = ax1.plot(df[xcolname], df[ycolname], 'o-', label=vparams['label'])
def make_tag_on_lines(df, rlist, dx, dy, color, ha='left'):
for r in rlist:
x, y = df.loc[r, xcolname], df.loc[r, ycolname]
ax1.annotate(f'r={r}', (x,y), (x+dx,y+dy), color=color, ha=ha, va='center')
ax1.axvline(0, color='gray', lw=1, ls='dotted')
for vname, vparams in plot_variants.items():
make_tag_on_lines(
recovery_df[vname], vparams['tag_locs'],
vparams['tag_dx'], vparams['tag_dy'],
lines[vname].get_color(),
ha=vparams['tag_ha'],
)
# ax1.scatter(recovery_df_raw[xcolname], recovery_df_raw[ycolname], marker="*", s=100)
ax1.legend(handlelength=2)
ax1.set_xlabel(r"Noise contamination (Spearman vs $S$)")
ax1.set_ylabel(r"Genetic recovery (Spearman vs $R_g$ where $|G| < 0.05$ )")
ycolname = "spearman_vs_noise"
x, xticks, xlabels = get_r_scaled(rank_list, scale="log2")
for vname, vparams in plot_variants.items():
df = recovery_df[vname]
ax2.plot(x, df[ycolname], 'o-', label=vparams['label'], color=lines[vname].get_color())
ax2.axhline(0, color='gray', lw=1, ls='dotted')
ax2.axhspan(0.26, 0.59, color=lines['identity'].get_color(), alpha=0.07)
ax2.set_xticks(xticks)
ax2.set_xticklabels(xlabels, rotation=90)
ax2.set_xlabel("Nuclear norm constraint r")
ax2.set_ylabel(r"Noise contamination (Spearman vs $S$)")
# outfile_name=f"figures/pgc_recovery_contamination_tradeoff_78_traits"
# plt.savefig(f"{outfile_name}.pdf", bbox_inches='tight')
# plt.savefig(f"{outfile_name}.png", bbox_inches='tight')
plt.show()