This notebook is part of a tutorial series for the FRETBursts burst analysis software.
For a step-by-step introduction to FRETBursts usage please refer to [us-ALEX smFRET burst analysis](FRETBursts - us-ALEX smFRET burst analysis.ipynb).
In this notebook we present a typical FRETBursts workflow for ns-ALEX smFRET burst analysis.
While FRETBursts does not specifically includes functions for fitting TCSPC fluorescence decays, a fitting with exponetial decays and IRF deconvolution can be easily performed using standard python libraries. For an example and a brief discussion see the notebook Lifetime decay fit.
from fretbursts import *
The following command will an open-file dialog in order to select a data file:
fname = gui_fname(r'C:\Data')
fname
Here we load the file and we set the alternation parameters:
d = loader.nsalex(fname)
d.time_max()
d.det_t
np.unique(d.det_t)
d.add(D_ON=(150, 1100), A_ON=(1200, 2050), det_donor_accept=(0, 2))
bpl.plot_alternation_hist_nsalex(d)
Execute the previous 2 cells untill you get a satisfying selection for the excitation periods. Then run the following to apply the parameters:
loader.nsalex_apply_period(d)
d.calc_bg(fun=bg.exp_fit, time_s=30, tail_min_us='auto', F_bg=1.7)
dplot(d, timetrace_bg)
dplot(d, timetrace_da)
xlim(1, 2)
ylim(-50, 50)
d.burst_search_t()
ds = Sel(d, select_bursts.size, th1=30)
dplot(ds, hist2d_alex)
ds.update_leakage(0.09)
dplot(ds, hist2d_alex)
dplot(ds, hist_fret_kde)
The nanotime for the measurement is saved in the .nanotime
attribute of the Data()
variable (here either d
or ds
).
As an example here we get the array of nanotimes for all photons, donor emission and acceptor emsission:
nanotimes_t = d.nanotimes
nanotimes_d = d.nanotimes[d.get_D_em()]
nanotimes_a = d.nanotimes[d.get_A_em()]
We can plot the histogram for this 3 nanotimes:
hist_params = dict(bins=range(4096), histtype='step', alpha=0.6, lw=1.5)
hist(nanotimes_t, color='k', label='Total ph.', **hist_params)
hist(nanotimes_d, color='g', label='D. em. ph.', **hist_params)
hist(nanotimes_a, color='r', label='A. em. ph.', **hist_params)
plt.legend()
xlim(0, 2000)
We can also select only nanotimes of photons inside bursts. Here, as an example, we will use the ds
variable that contains a selection of bursts.
First we compute a selection mask (a boolean array) for photons inside bursts:
ph_in_bursts_mask = bl.ph_select(ds.ph_times_m[0], ds.mburst[0])
Then we apply this selection to the nanotimes array. To get the donor- and acceptor-emission nanotimes we combine the in-bursts selection mask (ph_in_bursts_mask
) with the donor or acceptor emission mask (that we get with .get_D_em()
and .get_D_em()
):
bursts_nanotimes_t = d.nanotimes[ph_in_bursts_mask]
bursts_nanotimes_d = d.nanotimes[ph_in_bursts_mask * d.get_D_em()]
bursts_nanotimes_a = d.nanotimes[ph_in_bursts_mask * d.get_A_em()]
And, as before, we can histogram the nanotimes:
hist_params = dict(bins=range(4096), histtype='step', alpha=0.6, lw=1.5)
hist(bursts_nanotimes_t, color='k', label='Total ph.', **hist_params)
hist(bursts_nanotimes_d, color='g', label='D. em. ph.', **hist_params)
hist(bursts_nanotimes_a, color='r', label='A. em. ph.', **hist_params)
plt.legend()
xlim(0, 2000)
Saving some of all these arrays to file is straightforward. Let see some examples.
with open('nanotimes_t.txt', 'w') as f:
nanotimes_t.tofile(f, sep=',\n') # save in CSV txt format
To save a set of arrays in MATLAB format we can use the scipy.io.savemat
function.
Here we save 3 arrays bursts_nanotimes_t
, bursts_nanotimes_d
and bursts_nanotimes_a
to a file called bursts_nanotimes.mat:
from scipy.io import savemat
savemat('bursts_nanotimes.mat',
dict(bn_t=bursts_nanotimes_t,
bn_d=bursts_nanotimes_d,
bn_a=bursts_nanotimes_a,))
When loaded in MATLAB the arrays will be named bn_t
, bn_d
and bn_a
.
from IPython.core.display import HTML
HTML(open("./styles/custom.css", "r").read())