File size: 3,428 Bytes
2723b14 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | """Minimal static figures from measured posterior outcomes."""
import csv
import json
from pathlib import Path
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
HERE=Path(__file__).resolve().parent
def main():
root=HERE/'results/posterior'
rows=[json.loads(p.read_text()) for p in root.glob('*__*.json')]
rows.sort(key=lambda r:(r['case'],r['sensitivity_axis'],r['axis_value']))
keys=['case','setting','posterior_mean_deletions','posterior_mean_insertions',
'posterior_mean_substitutions','posterior_retained_source_fraction',
'ancestry_entropy_nats','known_correspondence_mean_probability',
'moving_region_deletion_probability','emissions_seconds','forward_dp_seconds',
'marginals_map_seconds','posterior_32_draw_seconds','process_peak_rss_MiB']
with (HERE/'results/posterior_table.csv').open('w') as f:
w=csv.DictWriter(f,fieldnames=keys);w.writeheader()
for r in rows:w.writerow({k:r.get(k,'') for k in keys})
plt.rcParams.update({'font.size':10, 'axes.spines.top':False,'axes.spines.right':False,
'pdf.fonttype':42,'ps.fonttype':42})
fig,ax=plt.subplots(1,3,figsize=(10,3.0),layout='constrained')
for case,label,color in [('identity_24_24','No motion','#666666'),
('moving_domain_24_24','Moving region','#31688e')]:
r=sorted([x for x in rows if x['case']==case and x['sensitivity_axis']=='diffusion'],
key=lambda x:x['axis_value'])
ax[0].plot([x['axis_value'] for x in r],
[100*x['moving_region_correct_probability'] for x in r],
marker='o',label=label,color=color)
ax[1].plot([x['axis_value'] for x in r],
[100*x['moving_region_deletion_probability'] for x in r],
marker='o',label=label,color=color)
ax[0].set_ylabel('Correct correspondence (%)');ax[0].set_ylim(-2,102)
ax[1].set_ylabel('Region replaced (%)');ax[1].set_ylim(-2,102)
ax[0].legend(frameon=False)
r=sorted([x for x in rows if x['case']=='natural_282_203' and x['sensitivity_axis']=='diffusion'],
key=lambda x:x['axis_value'])
for key,label,color in [('posterior_mean_deletions','Deletions','#a6611a'),
('posterior_mean_insertions','Insertions','#31688e')]:
ax[2].plot([x['axis_value'] for x in r],[x[key] for x in r],marker='o',label=label,color=color)
ax[2].set_ylabel('Expected residue edits');ax[2].legend(frameon=False)
for a in ax:
a.set_xscale('log',base=2);a.set_xticks([.5,1,2,4,8],[.5,1,2,4,8])
a.set_xlabel('Diffusion SD (Å / √time)')
fig.savefig(HERE/'results/posterior_sensitivity.pdf')
fig.savefig(HERE/'results/posterior_sensitivity.png',dpi=180)
plt.close(fig)
p=root/'natural_282_203__diffusion_2.npz'
if p.exists():
data=np.load(p)
fig,ax=plt.subplots(figsize=(5,4),layout='constrained')
im=ax.imshow(data['match'],origin='lower',aspect='auto',vmin=0,vmax=1,cmap='viridis')
ax.set_xlabel('Target residue');ax.set_ylabel('Source residue')
fig.colorbar(im,ax=ax,label='Persistence probability')
fig.savefig(HERE/'results/natural_correspondence.pdf')
fig.savefig(HERE/'results/natural_correspondence.png',dpi=180)
plt.close(fig)
if __name__=='__main__':main()
|