{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Working with timestamps and bursts\n", "\n", "*This notebook is part of a [tutorial series](https://github.com/OpenSMFS/FRETBursts_notebooks) for the [FRETBursts](http://opensmfs.github.io/FRETBursts/) burst analysis software.*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> In this notebook we show how to access different streams of timestamps,\n", "> burst data (i.e. start and stop times and indexes, counts, etc...).\n", "> These operations are useful for users wanting to access or process bursts data \n", "> and timestamps in custom ways.\n", "> For a complete tutorial on burst analysis see \n", "> [FRETBursts - us-ALEX smFRET burst analysis](FRETBursts - us-ALEX smFRET burst analysis.ipynb)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load data\n", "\n", "We start by loading the data, computing background and performing a standard burst search:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " - Optimized (cython) burst search loaded.\n", " - Optimized (cython) photon counting loaded.\n", "--------------------------------------------------------------\n", " You are running FRETBursts (version 0.7+46.ge31fadb.dirty).\n", "\n", " If you use this software please cite the following paper:\n", "\n", " FRETBursts: An Open Source Toolkit for Analysis of Freely-Diffusing Single-Molecule FRET\n", " Ingargiola et al. (2016). http://dx.doi.org/10.1371/journal.pone.0160716 \n", "\n", "--------------------------------------------------------------\n" ] } ], "source": [ "from fretbursts import *\n", "sns = init_notebook()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# Total photons (after ALEX selection): 2,259,522\n", "# D photons in D+A excitation periods: 721,537\n", "# A photons in D+A excitation periods: 1,537,985\n", "# D+A photons in D excitation period: 1,434,842\n", "# D+A photons in A excitation period: 824,680\n", "\n", " - Calculating BG rates ... Channel 0\n", "[DONE]\n", " - Performing burst search (verbose=False) ...[DONE]\n", " - Calculating burst periods ...[DONE]\n", " - Counting D and A ph and calculating FRET ... \n", " - Applying background correction.\n", " [DONE Counting D/A]\n" ] } ], "source": [ "filename = \"./data/0023uLRpitc_NTP_20dT_0.5GndCl.hdf5\"\n", "d = loader.photon_hdf5(filename)\n", "loader.alex_apply_period(d)\n", "d.calc_bg(bg.exp_fit, time_s=30, tail_min_us='auto', F_bg=1.7)\n", "d.burst_search()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting the timestamps\n", "\n", "To get the timestamps arrays for a given [photon stream](http://fretbursts.readthedocs.org/en/latest/ph_sel.html) we use [Data.get_ph_times](http://fretbursts.readthedocs.org/en/latest/data_class.html?highlight=get_ph_times#fretbursts.burstlib.Data.get_ph_times). Here a few example:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "ph = d.get_ph_times() # all the recorded photons\n", "ph_dd = d.get_ph_times(ph_sel=Ph_sel(Dex='Dem')) # donor excitation, donor emission\n", "ph_d = d.get_ph_times(ph_sel=Ph_sel(Dex='DAem')) # donor excitation, donor+acceptor emission\n", "ph_aa = d.get_ph_times(ph_sel=Ph_sel(Aex='Aem')) # acceptor excitation, acceptor emission" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This are streams of all timestamps (both inside and outside the bursts).\n", "Similarly, we can get \"masks\" of photons for each photon stream using \n", "[Data.get_ph_mask](http://fretbursts.readthedocs.org/en/latest/data_class.html?highlight=get_ph_mask#fretbursts.burstlib.Data.get_ph_mask):" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "mask_dd = d.get_ph_mask(ph_sel=Ph_sel(Dex='Dem')) # donor excitation, donor emission\n", "mask_d = d.get_ph_mask(ph_sel=Ph_sel(Dex='DAem')) # donor excitation, donor+acceptor emission\n", "mask_aa = d.get_ph_mask(ph_sel=Ph_sel(Aex='Aem')) # acceptor excitation, acceptor emission" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Masks are arrays of booleans (True or False values) which are True\n", "when the corresponding photon is in the stream. Note that all masks\n", "have same number of elements as the all-photons timestamps array:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(2259522, 2259522, 2259522, 2259522)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ph.size, mask_dd.size, mask_d.size, mask_aa.size" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Masks can be used to count photons in one stream:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1434842" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mask_d.sum()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and to obtain the timestamps for one stream:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 187345, 379190, 402492, ..., 47999838819,\n", " 47999862958, 47999954653])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ph[mask_d]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that the arrays `ph[mask_d]` and `ph_d` are equal. This is an important point to understand." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Burst data\n", "\n", "There are several fields containing burst data:\n", "\n", "**Start-stop**:\n", "\n", "- `Data.mburst`: start-stop information for each burst\n", "\n", "**Counts**:\n", "- `Data.nd`: donor detector counts during donor excitation\n", "- `Data.na`: acceptor detector counts during donor excitation\n", "- `Data.naa`: acceptor detector counts during acceptor excitation (ALEX only)\n", "- `Data.nda`: donor detector counts during acceptor excitation\n", "\n", "**FRET**:\n", "- `Data.E`: Proximity Ratio (when uncorrected) or FRET efficiency (when corrected)\n", "- `Data.S`: \"Stoichiometry\" (ALEX only)\n", "\n", "All previous fields are **lists** containing one element per excitation spot.\n", "In single-spot data, these lists have only one element which is accessed\n", "using the `[0]` notation:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "bursts = d.mburst[0]\n", "nd = d.nd[0]\n", "na = d.na[0]\n", "naa = d.naa[0]\n", "E = d.E[0]\n", "S = d.S[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All previous variables are numpy arrays, except for `bursts` which is\n", "a `Bursts` object (see next section)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Burst start and stop\n", "\n", "The start-stop burst data is in `bursts` (a variable of type [Bursts](), plural):" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
istartistopstartstop
015318950204885159285
118419451368935186298
221522461867696247541
324025064877946548720
432733986952378781357
...............
27589225922422592334799253231647992589568
27590225941122594334799793437747998022338
27591225944222594514799817139947998230689
27592225944922594594799821071047998281141
27593225949222595044799935025647999423370
\n", "

27594 rows × 4 columns

\n", "
" ], "text/plain": [ " istart istop start stop\n", "0 153 189 5020488 5159285\n", "1 184 194 5136893 5186298\n", "2 215 224 6186769 6247541\n", "3 240 250 6487794 6548720\n", "4 327 339 8695237 8781357\n", "... ... ... ... ...\n", "27589 2259224 2259233 47992532316 47992589568\n", "27590 2259411 2259433 47997934377 47998022338\n", "27591 2259442 2259451 47998171399 47998230689\n", "27592 2259449 2259459 47998210710 47998281141\n", "27593 2259492 2259504 47999350256 47999423370\n", "\n", "[27594 rows x 4 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bursts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Indexing `bursts` we can access a single burst:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
istartistopstartstop
015318950204885159285
\n", "
" ], "text/plain": [ " istart istop start stop\n", "0 153 189 5020488 5159285" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "firstburst = bursts[0]\n", "firstburst" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The first two \"columns\" (both in `bursts` or `firstburst`) are the index of \n", "**first** and **last** timestamps (relative to the all-photons timestamps).\n", "The last two columns (`start` and `stop`) are the actual times of burst \n", "start and stop. To access any of these fields we type:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 153, 184, 215, ..., 2259442, 2259449, 2259492])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bursts.istart" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([153])" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "firstburst.istart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that `ph[firstburst.istart]` is equal to `firstburst.start`:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([5020488]), array([5020488]))" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ph[firstburst.istart], firstburst.start" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The same holds for stop:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([5159285]), array([5159285]))" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ph[firstburst.istop], firstburst.stop" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that `bursts` is a `Bursts` object (plural, a bursts-set) \n", "and `firstburst` is a `Burst` object (singular, only one burst).\n", "You can find more info on these objects in the documentation:\n", "\n", "- [Low-level burst search functions](http://fretbursts.readthedocs.org/en/latest/burstsearch.html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Burst photon-counts\n", "\n", "The variables `nd`, `na`, `naa` contains the number of photon in different photon streams.\n", "By default these values are background corrected and, if the correction coefficients \n", "are specified, are also corrected for leakage, direct excitation and gamma factor.\n", "\n", "To get the raw counts before correction we can redo the burst search as follow:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " - Performing burst search (verbose=False) ...[DONE]\n", " - Calculating burst periods ...[DONE]\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/paul/anaconda3/envs/Py38/lib/python3.8/site-packages/fretbursts/burstlib.py:2876: RuntimeWarning: invalid value encountered in true_divide\n", " E = [na / (g * nd + na) for nd, na, g in zip(self.nd, self.na, G)]\n" ] } ], "source": [ "d.burst_search(computefret=False)\n", "d.calc_fret(count_ph=True, corrections=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that if you select bursts, you also need to use `computefret=False`\n", "to avoid recomputing E and S (which by default applies the corrections):" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "ds = d.select_bursts(select_bursts.size, th1=30, computefret=False)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "nd = ds.nd[0] # Donor-detector counts during donor excitation\n", "na = ds.na[0] # Acceptor-detector counts during donor excitation\n", "naa = ds.naa[0] # Acceptor-detector counts during acceptor excitation\n", "E = ds.E[0] # FRET efficiency or Proximity Ratio\n", "S = ds.S[0] # Stoichiometry, as defined in µs-ALEX experiments" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([31., 9., 22., ..., 16., 14., 9.])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that the burst counts are integer values, confirming that the background\n", "correction was not applied." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Slice bursts in time bins\n", "\n", "Here we slice each burst in fixed time bins." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "from fretbursts.phtools.burstsearch import Burst, Bursts" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "times = d.ph_times_m[0] # timestamps array" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start fusing bursts with separation <= 0 milliseconds,\n", "to avoid having overlapping bursts:" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " - - - - - CHANNEL 1 - - - - \n", " --> END Fused 196 bursts (5.8%, 3 iter)\n", "\n", " - Counting D and A ph and calculating FRET ... \n", " - Applying background correction.\n", " [DONE Counting D/A and FRET]\n", "\n", "Number of bursts: 3197\n" ] } ], "source": [ "ds_fused = ds.fuse_bursts(ms=0)\n", "bursts = ds_fused.mburst[0]\n", "print('\\nNumber of bursts:', bursts.num_bursts)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can slice each burst using a constant time bin:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "time_bin = 0.5e-3 # 0.5 ms" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "time_bin_clk = time_bin / ds.clk_p\n", "\n", "sub_bursts_list = []\n", "for burst in bursts:\n", " # Compute binning of current bursts\n", " bins = np.arange(burst.start, burst.stop + time_bin_clk, time_bin_clk)\n", " counts, _ = np.histogram(times[burst.istart:burst.istop+1], bins)\n", " \n", " # From `counts` in each bin, find start-stop times and indexes (sub-burst).\n", " # Note that start and stop are the min and max timestamps in the bin,\n", " # therefore they are not on the bin edges. Also the burst width is not\n", " # exactly equal to the bin width.\n", " sub_bursts_l = []\n", " sub_start = burst.start\n", " sub_istart = burst.istart\n", " for count in counts:\n", " # Let's skip bins with 0 photons\n", " if count == 0:\n", " continue\n", " \n", " sub_istop = sub_istart + count - 1\n", " sub_bursts_l.append(Burst(istart=sub_istart, istop=sub_istop,\n", " start=sub_start, stop=times[sub_istop]))\n", " \n", " sub_istart += count \n", " sub_start = times[sub_istart]\n", " \n", " sub_bursts = Bursts.from_list(sub_bursts_l)\n", " assert sub_bursts.num_bursts > 0\n", " assert sub_bursts.width.max() < time_bin_clk\n", " sub_bursts_list.append(sub_bursts)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The list `sub_bursts_list` has one set of sub-bursts per each original burst:" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3197" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(sub_bursts_list)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3197])" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds_fused.num_bursts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Each set of sub-bursts is a usual [Bursts](http://fretbursts.readthedocs.org/en/latest/burstsearch.html?highlight=burstsearchlib.bursts#fretbursts.burstsearch.burstsearchlib.Bursts) object:" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Sub-bursts from burst 0:\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
istartistopstartstop
015315350204885020488
115418150686275098971
218218451064975136893
318518951421915159285
\n", "
" ], "text/plain": [ " istart istop start stop\n", "0 153 153 5020488 5020488\n", "1 154 181 5068627 5098971\n", "2 182 184 5106497 5136893\n", "3 185 189 5142191 5159285" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print('Sub-bursts from burst 0:')\n", "sub_bursts_list[0]" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Sub-bursts from burst 10:\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
istartistopstartstop
01054810552250376538250402524
11055310566250422549250455792
21056710575250462410250483452
31057610581250498384250530441
41058210611250538483250575640
51061210622250578584250595726
61062310625250631455250643550
\n", "
" ], "text/plain": [ " istart istop start stop\n", "0 10548 10552 250376538 250402524\n", "1 10553 10566 250422549 250455792\n", "2 10567 10575 250462410 250483452\n", "3 10576 10581 250498384 250530441\n", "4 10582 10611 250538483 250575640\n", "5 10612 10622 250578584 250595726\n", "6 10623 10625 250631455 250643550" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iburst = 10\n", "print('Sub-bursts from burst %d:' % iburst)\n", "sub_bursts_list[iburst]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Photon counts in custom bursts\n", "\n", "When performing a burst search,\n", "FRETBursts automatically computes donor and acceptor counts (in both \n", "excitation periods). These quantities are available as `Data` attributes:\n", "`nd`, `na`, `naa` and `nda` (as described in [Burst data](#Burst-data)).\n", "\n", "When a custom bursts-set is created, like in the previous section in which we\n", "sliced bursts in sub-bursts, we may want to computed the photon counts \n", "in the various photon streams. Let consider, as an example, the following `Bursts` object:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
istartistopstartstop
015315350204885020488
115418150686275098971
218218451064975136893
318518951421915159285
\n", "
" ], "text/plain": [ " istart istop start stop\n", "0 153 153 5020488 5020488\n", "1 154 181 5068627 5098971\n", "2 182 184 5106497 5136893\n", "3 185 189 5142191 5159285" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bursts = sub_bursts_list[0]\n", "bursts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

How do we count the donor and acceptor photons in these bursts?

\n", "\n", "First we need to prepare the masks for the various photon streams \n", "(as explained [before](#Getting-the-timestamps)):" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "mask_dd = d.get_ph_mask(ph_sel=Ph_sel(Dex='Dem')) # donor excitation, donor emission\n", "mask_ad = d.get_ph_mask(ph_sel=Ph_sel(Dex='Aem')) # donor excitation, acceptor emission\n", "mask_aa = d.get_ph_mask(ph_sel=Ph_sel(Aex='Aem')) # acceptor excitation, acceptor emission" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we use the function `counts_ph_in_bursts`:" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "from fretbursts.phtools.burstsearch import count_ph_in_bursts" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0, 25, 2, 4], dtype=int32)" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "counts_dd = count_ph_in_bursts(bursts, mask_dd)\n", "counts_dd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`counts_dd` contains the raw counts in each burst (in `bursts`)\n", "in the Donor-emission during Donor-acceptor stream. Similarly,\n", "we can compute counts for the other photon streams:" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "counts_ad = count_ph_in_bursts(bursts, mask_ad)\n", "counts_aa = count_ph_in_bursts(bursts, mask_aa)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With these values, we can compute, for example, the uncorrected\n", "Proximity Ratio (PR):" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_31012/2104473605.py:1: RuntimeWarning: invalid value encountered in true_divide\n", " counts_ad / (counts_dd + counts_ad)\n" ] }, { "data": { "text/plain": [ "array([ nan, 0.07407407, 0. , 0.2 ])" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "counts_ad / (counts_dd + counts_ad)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that the first value is `nan` (not-a-number) because there\n", "is a zero in the numerator, i.e. the first bursts has 0 donor counts\n", "during donor excitation.\n", "\n", "Finally, remember that no correction (background, leakage, etc.) has been \n", "applied so far." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# See also\n", "\n", "This section of the documentation has more info how to use `Bursts` objects:\n", "\n", "- [Low-level burst search functions](http://fretbursts.readthedocs.org/en/latest/burstsearch.html)\n", "\n", "In particular, these 3 methods, allow transforming bursts to refer a new timestamps arrays:\n", "\n", "- [Bursts.recompute_times](http://fretbursts.readthedocs.org/en/latest/burstsearch.html?highlight=recompute_times#fretbursts.burstsearch.burstsearchlib.Bursts.recompute_times)\n", "- [Bursts.recompute_index_expand](http://fretbursts.readthedocs.org/en/latest/burstsearch.html?highlight=recompute_index_expand#fretbursts.burstsearch.burstsearchlib.Bursts.recompute_index_expand)\n", "- [Bursts.recompute_index_reduce](http://fretbursts.readthedocs.org/en/latest/burstsearch.html?highlight=recompute_index_reduce#fretbursts.burstsearch.burstsearchlib.Bursts.recompute_index_reduce)\n", "\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.13" }, "toc": { "colors": { "hover_highlight": "#DAA520", "running_highlight": "#FF0000", "selected_highlight": "#FFD700" }, "moveMenuLeft": true, "nav_menu": { "height": "174px", "width": "252px" }, "navigate_menu": true, "number_sections": false, "sideBar": true, "threshold": 4, "toc_cell": false, "toc_section_display": "block", "toc_window_display": false, "widenNotebook": false } }, "nbformat": 4, "nbformat_minor": 1 }