pyALEX Reference

class pyALEX.ALEX_bursts(D_D, D_A, A_D, A_A, burst_starts, burst_ends)[source]

This class holds single molecule burst data. Photon bursts are stored in numpy arrays. There is a separate array for each of the four photon streams, for the start and end of each burst and for the burst duration.

The four attributes corresponding to bursts from the four photon streams from an ALEX experiment are numpy arrays:

  • D_D: Donor channel when the donor laser is on
  • D_A: Donor channel when the acceptor laser is on
  • A_D: Acceptor channel when the donor laser is on
  • A_A: Acceptor channel when the acceptor laser is on

The three further attributes, corresponding to burst duration, burst start time and burst end time are also numpy arrays:

  • burst_len: Length (in bins) of each identified burst
  • burst_starts: Start time (bin number) of each identified burst
  • burst_ends: End time (bn number) of each identified burst

The class can be initialized directly from six lists or arrays: four of photon counts, the burst start times and the burst end times: bursts = ALEX_bursts(D_D_events, D_A_events, A_D_events, A_A_events, burst_starts, burst_ends).

However, it is more typically achieved by running the APBS or DCBS algorithm that forms part of the ALEX_data class.

denoise_bursts(N_DD, N_DA, N_AD, N_AA)[source]

Subtract background noise from ALEX bursts.

Arguments:

  • N_DD: average noise per time-bin in the channel D_D
  • N_DA: average noise per time-bin in the channel D_A
  • N_AD: average noise per time-bin in the channel A_D
  • N_AA: average noise per time-bin in the channel A_A
scatter_intensity(filepath, imgname, imgtype='pdf', labels=['Burst Duration', 'Burst Intensity'])[source]

Plot a scatter plot of burst brightness vs burst duration

Arguments: * filepath: file path to the directory in which the image will be saved * imgname: name under which the image will be saved

Keyword arguments: * imgtype: filetype of histogram image. Accepted values: jpg, tiff, rgba, png, ps, svg, eps, pdf * labels: labels for x and y axes, as a 2-element list of strings: [“x-title”, “y-title”]. Default value: [“Burst Duration”, “Burst Intensity”]

class pyALEX.ALEX_data(D_D, D_A, A_D, A_A)[source]

This class holds single molecule data.

It has four attributes, corresponding to the four photon streams from an ALEX experiment. These are numpy arrays:

  • D_D: Donor channel when the donor laser is on
  • D_A: Donor channel when the acceptor laser is on
  • A_D: Acceptor channel when the donor laser is on
  • A_A: Acceptor channel when the acceptor laser is on

It can be initialized from four lists or four arrays of photon counts: data = FRET_data(D_D_events, D_A_events, A_D_events, A_A_events)

APBS(T, M, L)[source]

All-photon bust search algorithm as implemented in Nir et al. J Phys Chem B. 2006 110(44):22103-24. Calls _runningMean and _APBS_bursts. Returns an ALEX_bursts object.

Arguments: * T: time-window (in bins) over which to sum photons (integer) * M: number of photons in window of length T required to identify a potential burst (integer) * L: total number of photons required for an identified burst to be accepted (integer)

From Nir et al.: The start (respectively, the end) of a potential burst is detected when the number of photons in the averaging window of duration T is larger (respectively, smaller) than the minimum number of photons M. A potential burst is retained if the number of photons it contains is larger than a minimum number L.

DCBS(T, M, L)[source]

Dual-channel bust search algorithm as implemented in Nir et al. J Phys Chem B. 2006 110(44):22103-24. Returns an ALEX_bursts object.

Arguments: * T: time-window (in bins) over which to sum photons * M: number of photons in window of length T required to identify a potential burst. * L: total number of photons required for an identified burst to be accepted.

From Nir et al.: The start (respectively, the end) of a potential burst is detected when the number of photons in the averaging window of duration T is larger (respectively, smaller) than the minimum number of photons M. A potential burst is retained if the number of photons it contains is larger than a minimum number L.

build_histogram(filepath, csvname, gamma=1.0, S_min=0.1, S_max=1.0, bin_min=0.0, bin_max=1.0, bin_width=0.02, image=False, imgname=None, imgtype=None, gauss=True, gaussname=None, n_gauss=1)[source]

Build a proximity ratio histogram and save the frequencies and bin centres as a csv file. Optionally plot and save a graph and perform a simple gaussian fit.

Arguments:

  • filepath: path to folder where the histogram will be saved (as a string)
  • csvname: the name of the file in which the histogram will be saved (as a string)

Keyword arguments:

  • gamma: Instrumental gamma factor. (float, default value 1.0)
  • S_min: the miniumum stoichiometric value for which to accept a burst (default 0.1)
  • S_max: the maximum stoichiometric value for which to accept a burst (default 0.9)
  • bin_min: the minimum value for a histogram bin (default 0.0)
  • bin_max: the maximum value for a histogram bin (default 1.0)
  • bin_width: the width of one bin (default 0.02)
  • image: Boolean. True plots a graph of the histogram and saves it (default False)
  • imgname: the name of the file in which the histogram graph will be saved (as a string)
  • imgtype: filetype of histogram image. Accepted values: jpg, tiff, rgba, png, ps, svg, eps, pdf
  • gauss: Boolean. True will fit the histogram with a single gaussian distribution (default False)
  • gaussname: the name of the file in which the parameters of the Gaussian fit will be saved
  • n_gauss: number of Gaussain distributions to fit. Default = 1
proximity_ratio(gamma=1.0)[source]

Calculate the proximity ratio (E) and return an array of values.

Arguments: None

Keyword arguments: gamma (default value 1.0): the instrumental gamma-factor

Calculation: E = nA / (nA + gamma*nD) for nA and nD photons in the acceptor (A_D) and donor (D_D) channels respectively

scatter_hist(S_min, S_max, gamma=1.0, save=False, filepath=None, imgname=None, imgtype=None)[source]

Plot a scatter plot of E (proximity ratio) vs S (stoichiometry) and projections of selected E and S values

Arguments:

  • S_min: minimum accepted value of S (float between 0 and 1)
  • S_max: maximum accepted value of S (float between 0 and 1)

Keyword arguments:

  • gamma: Instrumental gamma factor. (float, default value 1.0)
  • save: Boolean. True will save an image of the graph plotted (default False)
  • filepath: file path to the directory in which the image will be saved (default None)
  • imgname: name under which the image will be saved (default None)
  • imgtype: filetype of histogram image. Accepted values: jpg, tiff, rgba, png, ps, svg, eps, pdf
stoichiometry(gamma=1.0)[source]

Calculate the stoichiometry (S) and return an array of values.

Arguments: None

Keyword arguments: gamma (default value 1.0): the instrumental gamma-factor

Calculation: S = (gamma*D_D + A_D) / (gamma*D_D + A_D + A_A)

stoichiometry_selection(S, S_min, S_max)[source]

Select data with photons above a threshold.

Arguments:

  • S: array of stoichiometry values calculated using the stoichiometry method
  • S_min: minimum accepted value of S (float)
  • S_max: maximum accepted value of S (float)

Event selection criterion: Smin < Sx < Smax, for Stoichiometry Sx of event x

subtract_bckd(bckd_D_D, bckd_D_A, bckd_A_D, bckd_A_A)[source]

Subtract background noise from the four data channels.

Arguments:

  • bckd_D_D: average noise per time-bin in the channel D_D
  • bckd_D_A: average noise per time-bin in the channel D_A
  • bckd_A_D: average noise per time-bin in the channel A_D
  • bckd_A_A: average noise per time-bin in the channel A_A
subtract_crosstalk(l, d)[source]

Subtract crosstalk from the FRET channel A_D

Arguments:

  • l: leakage constant from donor channel D_D to acceptor channel A_D (float between 0 and 1)
  • d: direct excitation of the acceptor by the donor laser (float between 0 and 1)
thresholder(T_D, T_A)[source]

Select events that have photons above a threshold.

Arguments:

  • T_D: threshold for photons during donor laser excitation
  • T_A: threshold for photons during acceptor laser excitation

An event is above threshold if nA_D + nD_D > T_D AND nA_A > T_A for nA_D, nD_D and nA_A photons in the channels A_D, D_D and A_A respectively

pyALEX.fit_mixture(data, ncomp=1)[source]

Fit data using Gaussian mixture model

Arguments:

  • data: data to be fitted, as a numpy array

Key-word arguments:

  • ncomp (default value 1): number of components in the mixture model.
pyALEX.parse_bin(filepath, filelist, bits=16)[source]

Read data from a list of binary files and return an ALEX_data object.

Arguments: * filepath: the path to the folder containing the files * filelist: list of files to be analysed

Keyword arguments: * bits (default value 16): the number of bits used to store a donor-acceptor pair of time-bins

Note: This file structure is probably specific to the Klenerman group’s .dat files.
Please don’t use it unless you know you have the same filetype!
pyALEX.parse_csv(filepath, filelist, delimiter=', ')[source]

Read data from a list of csv and return a FRET_data object.

Arguments:

  • filepath: the path to the folder containing the files
  • filelist: list of files to be analysed

Keyword arguments:

  • delimiter (default ”,”): the delimiter between values in a row of the csv file.

This function assumes that each row of your file has the format: “D_D,D_A,A_D,A_A”

If your data does not have this format (for example if you have separate files for donor and acceptor data), this function will not work well for you.