FRETBursts - 8-spot smFRET burst analysis

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.

In this notebook we present a typical FRETBursts workflow for multi-spot smFRET burst analysis. Briefly, we show how to perform background estimation, burst search, burst selection, FRET histograms, and FRET efficiency fit using different methods.

Loading the software

In [1]:
from fretbursts import *
 - Optimized (cython) burst search loaded.
 - Optimized (cython) photon counting loaded.
--------------------------------------------------------------
 You are running FRETBursts (version 0.5.7+0.g7267863.dirty).

 If you use this software please cite the following paper:

   FRETBursts: An Open Source Toolkit for Analysis of Freely-Diffusing Single-Molecule FRET
   Ingargiola et al. (2016). http://dx.doi.org/10.1371/journal.pone.0160716 

--------------------------------------------------------------
In [2]:
sns = init_notebook()
In [3]:
import lmfit; lmfit.__version__
Out[3]:
'0.9.5'
In [4]:
import phconvert; phconvert.__version__
Out[4]:
'0.7.1'

Downloading the sample data file

The complete example dataset can be downloaded from here.

Here we download an 8-spot smFRET measurement file using the download_file in FRETBursts:

In [5]:
url = 'http://files.figshare.com/2182604/12d_New_30p_320mW_steer_3.hdf5'
In [6]:
download_file(url, save_dir='./data')
URL:  http://files.figshare.com/2182604/12d_New_30p_320mW_steer_3.hdf5
File: 12d_New_30p_320mW_steer_3.hdf5
 
File already on disk: /Users/anto/src/FRETBursts/notebooks/data/12d_New_30p_320mW_steer_3.hdf5 
Delete it to re-download.

Selecting a data file

In [7]:
filename = "./data/12d_New_30p_320mW_steer_3.hdf5"
In [8]:
import os
assert os.path.exists(filename)

Load and process the data:

In [9]:
d = loader.photon_hdf5(filename)

For convenience we can set the correction coefficients right away so that they will be used in the subsequent analysis. The correction coefficients are:

  • leakage or bleed-through: leakage
  • direct excitation: dir_ex (ALEX-only)
  • gamma-factor gamma

The direct excitation cannot be applied to non-ALEX (single-laser) smFRET measurements (like the current one).

In [10]:
d.leakage = 0.038
d.gamma = 0.43

NOTE: at any later moment, after burst search, a simple reassignment of these coefficient will update the burst data with the new correction values.

Compute background and burst search:

In [11]:
d.calc_bg(bg.exp_fit, time_s=30, tail_min_us='auto', F_bg=1.7)
d.burst_search(L=10, m=10, F=7)
 - Calculating BG rates ... [DONE]
 - Performing burst search (verbose=False) ...[DONE]
 - Calculating burst periods ...[DONE]
 - Counting D and A ph and calculating FRET ... 
   - Applying background correction.
   - Applying leakage correction.
   [DONE Counting D/A]

Perform a background plot as a function of the channel:

In [12]:
mch_plot_bg(d)

Let's take a look at the photon waiting times histograms and at the fitted background rates:

In [13]:
dplot(d, hist_bg);

Using dplot exactly in the same way as for the single-spot data has now generated 8 subplots, one for each channel.

Let's plot a timetrace for the background to see is there are significant variations during the measurement:

In [14]:
dplot(d, timetrace_bg);

We can look at the timetrace of the photon stream (binning):

In [15]:
dplot(d, timetrace)
xlim(2, 3); ylim(-100, 100);

We can also open the same plot in an interactive window that allows scrolling (uncomment the following lines):

In [16]:
#%matplotlib qt
In [17]:
#dplot(d, timetrace, scroll=True);
In [18]:
#ylim(-100, 100)
In [19]:
#%matplotlib inline

Burst selection and FRET

Selecting bursts by burst size (select_bursts.size)

In [20]:
gamma = d.gamma
gamma
Out[20]:
array(0.43)
In [21]:
d.gamma = 1
ds = d.select_bursts(select_bursts.size, th1=30, gamma=1)
dplot(ds, hist_fret);
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9818 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 12230 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10948 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10732 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10197 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10752 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9640 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9818 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 12230 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10948 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10732 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10197 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10752 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9640 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
In [22]:
ds = d.select_bursts(select_bursts.size, th1=25, gamma=gamma, donor_ref=False)
dplot(ds, hist_fret);
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9818 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 12230 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10948 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10732 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10197 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10752 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9640 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9818 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 12230 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10948 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10732 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10197 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10752 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9640 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
In [23]:
ds = d.select_bursts(select_bursts.size, th1=25, gamma=gamma)
dplot(ds, hist_fret, weights='size', gamma=gamma);
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9818 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 12230 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10948 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10732 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10197 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10752 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/burstlib.py:2114: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9640 but corresponding boolean dimension is 9073
  ds[name][ich] = self[name][ich][mask]
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9818 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 12230 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10948 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10732 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10197 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 10752 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
/Users/anto/miniconda3/lib/python3.5/site-packages/fretbursts/phtools/burstsearch.py:336: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 9640 but corresponding boolean dimension is 9073
  return self.__class__(self.data[i])
In [24]:
dplot(ds, scatter_fret_nd_na); ylim(0,200);

FRET Fitting

2-Gaussian mixture

Let's fit the $E$ histogram with a 2-Gaussians model:

In [25]:
ds.gamma = 1.
bext.bursts_fitter(ds, weights=None)
ds.E_fitter.fit_histogram(mfit.factory_two_gaussians(), verbose=False)

The fitted parameters are stored in a pandas DataFrame:

In [26]:
ds.E_fitter.params
Out[26]:
p1_amplitude p1_center p1_sigma p2_amplitude p2_center p2_sigma
0 0.161092 0.0148174 0.0551037 0.827499 0.587952 0.14408
1 0.243272 0.0323764 0.11476 0.763416 0.584405 0.190855
2 0.249805 0.00518158 0.0728283 0.742059 0.498093 0.2
3 0.213433 0.0087562 0.075682 0.786335 0.541668 0.191265
4 0.214548 0.0233083 0.0879623 0.789166 0.549135 0.189851
5 0.219882 0.022783 0.0921309 0.788298 0.534499 0.196293
6 0.202031 0.00635976 0.0719399 0.793649 0.530005 0.1815
7 0.225964 0.0201277 0.0872862 0.775101 0.529871 0.173377
In [27]:
dplot(ds, hist_fret, weights=None, show_model=True,
      show_fit_stats=True, fit_from='p2_center');