changed example punit

This commit is contained in:
2025-05-20 00:12:23 +02:00
parent 2e3d373100
commit ee2b8f98b7
18 changed files with 232 additions and 149 deletions

View File

@@ -6,6 +6,11 @@ from pathlib import Path
from plotstyle import plot_style, labels_params, significance_str
model_cells = ['2017-07-18-ai-invivo-1', # strong triangle
'2012-12-13-ao-invivo-1', # triangle
'2012-12-20-ac-invivo-1', # weak border triangle
'2013-01-08-ab-invivo-1'] # no triangle
data_path = Path('data')
sims_path = data_path / 'simulations'
@@ -70,7 +75,7 @@ def plot_chi2(ax, s, data_file):
def plot_chi2_contrasts(axs, s, cell_name):
print(cell_name)
print(f' {cell_name}')
files, nums = sort_files(cell_name,
sims_path.glob(f'chi2-split-{cell_name}-*.npz'), 1)
plot_chi2(axs[0], s, files[-1])
@@ -81,21 +86,21 @@ def plot_chi2_contrasts(axs, s, cell_name):
def plot_nli_cv(ax, s, data, alpha, cells):
data = data[data('contrast') == alpha, :]
r, p = pearsonr(data('cvbase'), data[:, 'dnli'])
l = linregress(data('cvbase'), data[:, 'dnli'])
data = data[data['contrast'] == alpha, :]
r, p = pearsonr(data['cvbase'], data['dnli'])
l = linregress(data['cvbase'], data['dnli'])
x = np.linspace(0, 1, 10)
ax.set_visible(True)
ax.set_title(f'$c$={100*alpha:g}\\,\\%', fontsize='medium')
ax.axhline(1, **s.lsLine)
ax.plot(x, l.slope*x + l.intercept, **s.lsGrid)
mask = data('triangle') > 0.5
mask = data['triangle'] > 0.5
ax.plot(data[mask, 'cvbase'], data[mask, 'dnli'],
clip_on=False, zorder=30, label='strong', **s.psA1m)
mask = data[:, 'border'] > 0.5
mask = data['border'] > 0.5
ax.plot(data[mask, 'cvbase'], data[mask, 'dnli'],
zorder=20, label='weak', **s.psA2m)
ax.plot(data[:, 'cvbase'], data[:, 'dnli'], clip_on=False,
ax.plot(data['cvbase'], data['dnli'], clip_on=False,
zorder=10, label='none', **s.psB1m)
for cell_name in cells:
@@ -124,7 +129,7 @@ def plot_nli_cv(ax, s, data, alpha, cells):
title='triangle', handlelength=0.5,
handletextpad=0.5, labelspacing=0.2)
kde = gaussian_kde(data('dnli'), 0.15/np.std(data('dnli'), ddof=1))
kde = gaussian_kde(data['dnli'], 0.15/np.std(data['dnli'], ddof=1))
nli = np.linspace(0, 8, 100)
pdf = kde(nli)
dax = ax.inset_axes([1.04, 0, 0.3, 1])
@@ -137,34 +142,35 @@ def plot_summary_contrasts(axs, s, cells):
nli_thresh = 1.2
data = TableData(data_path / 'Apteronotus_leptorhynchus-Punit-models.csv')
plot_nli_cv(axs[0], s, data, 0, cells)
print('split:')
nli_split = data[data('contrast') == 0, 'dnli']
print(f' mean NLI = {np.mean(nli_split):.2f}, stdev = {np.std(nli_split):.2f}')
print('noise split:')
cdata = data[data['contrast'] == 0, :]
nli_split = cdata['dnli']
print(f' mean SI = {np.mean(nli_split):.2f}, stdev = {np.std(nli_split):.2f}')
n = np.sum(nli_split > nli_thresh)
print(f' {n} cells ({100*n/len(nli_split):.1f}%) have NLI > {nli_thresh:.1f}')
print(f' triangle cells have nli >= {np.min(nli_split[data[data("contrast") == 0, "triangle"] > 0.5])}')
print(f' {n} cells ({100*n/len(nli_split):.1f}%) have SI > {nli_thresh:.1f}:')
for name, cv in cdata[nli_split > nli_thresh, ['cell', 'cvbase']].row_data():
print(f' {name:<22} CV={cv:4.2f}')
print(f' triangle cells have SI >= {np.min(nli_split[cdata["triangle"] > 0.5]):.2f}')
print()
for i, a in enumerate([0.01, 0.03, 0.1]):
plot_nli_cv(axs[1 + i], s, data, a, cells)
print(f'contrast {100*a:2g}%:')
cdata = data[data('contrast') == a, :]
nli = cdata('dnli')
cdata = data[data['contrast'] == a, :]
nli = cdata['dnli']
r, p = pearsonr(nli_split, nli)
print(f' correlation with split: r={r:.2f}, p={p:.1e}')
print(f' mean NLI = {np.mean(nli):.2f}, stdev = {np.std(nli):.2f}')
print(f' mean SI = {np.mean(nli):.2f}, stdev = {np.std(nli):.2f}')
n = np.sum(nli > nli_thresh)
print(f' {n} cells ({100*n/len(nli):.1f}%) have NLI > {nli_thresh:.1f}')
print( ' CVs:', cdata[nli > nli_thresh, 'cvbase'])
print( ' names:', cdata[nli > nli_thresh, 'cell'])
print(f' {n} cells ({100*n/len(nli):.1f}%) have SI > {nli_thresh:.1f}:')
for name, cv in cdata[nli > nli_thresh, ['cell', 'cvbase']].row_data():
print(f' {name:<22} CV={cv:4.2f}')
print(f' triangle cells have SI >= {np.min(nli[cdata["triangle"] > 0.5]):.2f}')
print()
print('lowest baseline CV:', np.unique(data('cvbase'))[:3])
print('overall lowest baseline CV:',
' '.join([f'{cv:.2f}' for cv in np.unique(data['cvbase'])[:5]]))
if __name__ == '__main__':
cells = ['2017-07-18-ai-invivo-1', # strong triangle
'2012-12-13-ao-invivo-1', # triangle
'2012-12-20-ac-invivo-1', # weak border triangle
'2013-01-08-ab-invivo-1'] # no triangle
s = plot_style()
#labels_params(xlabelloc='right', ylabelloc='top')
fig, axs = plt.subplots(6, 4, cmsize=(s.plot_width, 0.95*s.plot_width),
@@ -173,12 +179,14 @@ if __name__ == '__main__':
wspace=1, hspace=0.7)
for ax in axs.flat:
ax.set_visible(False)
for k in range(len(cells)):
plot_chi2_contrasts(axs[k], s, cells[k])
print('Example cells:')
for k in range(len(model_cells)):
plot_chi2_contrasts(axs[k], s, model_cells[k])
for k in range(4):
fig.common_yticks(axs[k, :])
fig.common_xticks(axs[:4, k])
plot_summary_contrasts(axs[5], s, cells)
print()
plot_summary_contrasts(axs[5], s, model_cells)
fig.common_yticks(axs[5, :])
fig.tag(axs, xoffs=-4.5, yoffs=1.8)
fig.savefig()