<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Executed
Step1:  To recompute the PR data used by this notebook run the 
8-spots paper analysis notebook.
Computation
Step2:  Create Leakage Table
Step3:  Average leakage coefficient
Step4:  Conclusions
Either averaging $E_{PR}$ or the corresponding $k = n_d/n_a$ the result for the leakage coefficient is ~10 % (D-only peak fitted finding the maximum of the KDE).
Save data
Full table
Step5:  Average coefficient
<ASSISTANT_TASK:>
Python Code:
#bsearch_ph_sel = 'all-ph'
#bsearch_ph_sel = 'Dex'
bsearch_ph_sel = 'DexDem'
data_file = 'results/usALEX-5samples-PR-raw-%s.csv' % bsearch_ph_sel
Explanation: Executed: Mon Mar 27 11:37:02 2017
Duration: 3 seconds.
Leakage coefficient fit
This notebook estracts the leakage coefficient from the set of 5 us-ALEX smFRET measurements.
What it does?
For each measurement, we fit the donor-only peak position of the uncorrected proximity ratio histogram. These values are saved in a .txt file. This notebook just performs a weighted mean where the weights are the number of bursts in each measurement.
This notebook read data from the file:
End of explanation
from __future__ import division
import numpy as np
import pandas as pd
from IPython.display import display
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
%config InlineBackend.figure_format='retina'  # for hi-dpi displays
sns.set_style('whitegrid')
palette = ('Paired', 10)
sns.palplot(sns.color_palette(*palette))
sns.set_palette(*palette)
data = pd.read_csv(data_file).set_index('sample')
data
display(data[['E_pr_do_gauss', 'E_pr_do_kde', 'E_pr_do_hsm', 'n_bursts_do']])
print('KDE Mean (%):     ', data.E_pr_do_kde.mean()*100)
print('KDE Std. Dev. (%):', data.E_pr_do_kde.std()*100)
d = data[['E_pr_do_gauss', 'E_pr_do_kde', 'E_pr_do_hsm']]#, 'n_bursts_do']]
d.plot(lw=3);
Explanation: To recompute the PR data used by this notebook run the 
8-spots paper analysis notebook.
Computation
End of explanation
E_table = data[['E_pr_do_gauss', 'E_pr_do_kde']]
E_table
lk_table = E_table / (1 - E_table)
lk_table.columns = [c.replace('E_pr_do', 'lk') for c in E_table.columns]
lk_table['num_bursts'] = data['n_bursts_do']
lk_table
Explanation: Create Leakage Table
End of explanation
data.E_pr_do_kde
lk_table.lk_kde
E_m = np.average(data.E_pr_do_kde, weights=data.n_bursts_do)
E_m
k_E_m = E_m / (1 - E_m)
k_E_m
k_m = np.average(lk_table.lk_kde, weights=data.n_bursts_do)
k_m
Explanation: Average leakage coefficient
End of explanation
stats = pd.concat([lk_table.mean(), lk_table.std()], axis=1, keys=['mean', 'std']).T
stats
table_to_save = lk_table.append(stats)
table_to_save = table_to_save.round({'lk_gauss': 5, 'lk_kde': 5, 'num_bursts': 2})
table_to_save
table_to_save.to_csv('results/table_usalex_5samples_leakage_coeff.csv')
Explanation: Conclusions
Either averaging $E_{PR}$ or the corresponding $k = n_d/n_a$ the result for the leakage coefficient is ~10 % (D-only peak fitted finding the maximum of the KDE).
Save data
Full table
End of explanation
'%.5f' % k_m
with open('results/usALEX - leakage coefficient %s.csv' % bsearch_ph_sel, 'w') as f:
    f.write('%.5f' % k_m)
Explanation: Average coefficient
End of explanation
<END_TASK>