{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "**TRamWAy** - The Random Walk Analyzer - features tools for processing single-molecule localization microscopy data.\n", "\n", "***\n", "\n", "
\n", "\n", "***\n", "\n", "This notebook introduces the [RWAnalyzer](https://tramway.readthedocs.io/en/master/tramway.analyzer.html#tramway.analyzer.RWAnalyzer) object and its main functionalities, as of version *0.5*.\n", "\n", "#### Table of contents\n", "* [Parameter maps](#Parameter-maps)\n", "* [SPT analysis and data structures](#SPT-analysis-and-data-structures)\n", "* [Locations, trajectories and translocations](#Locations,-trajectories-and-translocations)\n", "* [ROI definition](#ROI-definition)\n", "* [Tessellation](#Tessellation), [time segmentation](#Time-segmentation) and [sampling](#Sampling)\n", "* [Parameter estimation](#Parameter-estimation)\n", " * [DV inference](#DV-inference)\n", " * [Custom mappers](#Custom-mappers)\n", " * [Analyzing trajectories](#Analyzing-trajectories)\n", " * [Embarrassingly parallel mapper functions](#Embarrassingly-parallel-mapper-functions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us first download the data required by this notebook:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from tutorial import *\n", "\n", "download_RWAnalyzer_tour_data()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook also requires some extra dependencies, including `scikit-learn` (required), `stopit` (optional) and those listed in the `roi` installation target for TRamWAy (only `polytope` is required).\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: polytope in /home/francois/Projects/TRamWAy/lib/python3.8/site-packages (0.2.3)\n", "Requirement already satisfied: cvxopt in /home/francois/Projects/TRamWAy/lib/python3.8/site-packages (1.3.0)\n", "Requirement already satisfied: stopit in /home/francois/Projects/TRamWAy/lib/python3.8/site-packages (1.1.2)\n", "Requirement already satisfied: scikit-learn in /home/francois/Projects/TRamWAy/lib/python3.8/site-packages (1.2.2)\n", "Requirement already satisfied: scipy>=0.18.0 in /home/francois/Projects/TRamWAy/lib/python3.8/site-packages (from polytope) (1.10.1)\n", "Requirement already satisfied: numpy>=1.10.0 in /home/francois/Projects/TRamWAy/lib/python3.8/site-packages (from polytope) (1.24.2)\n", "Requirement already satisfied: networkx>=1.6 in /home/francois/Projects/TRamWAy/lib/python3.8/site-packages (from polytope) (3.0)\n", "Requirement already satisfied: threadpoolctl>=2.0.0 in /home/francois/Projects/TRamWAy/lib/python3.8/site-packages (from scikit-learn) (3.1.0)\n", "Requirement already satisfied: joblib>=1.1.1 in /home/francois/Projects/TRamWAy/lib/python3.8/site-packages (from scikit-learn) (1.2.0)\n" ] } ], "source": [ "import sys\n", "\n", "!\"{sys.executable}\" -m pip install polytope cvxopt stopit scikit-learn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook introduces (again) some basic concepts of the TRamWAy approach.\n", "\n", "Some of the models inherited from InferenceMAP are used to estimate parameters of the dynamics of the fluorescent particles in the imaged biological sample. Such models focus on resolving the dynamics in space (and time), and are fed with individual displacements instead of entire trajectories.\n", "\n", "Nevertheless, TRamWAy also features tools for extracting and quantifying trajectories, and two sections are dedicated to this topic.\n", "\n", "Back to the mere TRamWAy approach that consists of resolving the dynamics in space, let us first have a look to example parameter maps." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Parameter maps\n", "A key product TRamWAy generates out of single particle tracking data is a collection of parameter maps that quantify the local dynamics of the observed molecules and their environment.\n", "\n", "Let us load a data file and visualize one such map before we dive into the details of getting these parameters:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from tramway.analyzer import *\n", "\n", "a = RWAnalyzer()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "a.spt_data.from_rwa_file('data-examples/demo1.rwa')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A *.rwa* file also stores the result of analyses on these data.\n", "\n", "For example this file contains effective potential maps. Let us visualize them:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# retrieve parameter maps\n", "sampling_label = 'gwr + 60s windowing'\n", "sampling = a.spt_data.get_sampling(sampling_label)\n", "map_label = 'dv d=50 v=2 (ns)'\n", "maps = sampling.get_child(map_label)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# reload the time segmentation used to generate the maps\n", "a.time.from_sampling(sampling)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "%%capture\n", "# initialize the movie for a parameter map\n", "import matplotlib.pyplot as plt\n", "\n", "fig, ax = plt.subplots(figsize=(8,7))\n", "\n", "movie = a.mapper.mpl.animate(fig, maps, feature='potential',\n", " axes=ax, unit='std', overlay_locations=True)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", " | n | \n", "x | \n", "y | \n", "t | \n", "dx | \n", "dy | \n", "dt | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "3 | \n", "41.0294 | \n", "7.0758 | \n", "20.48 | \n", "0.0453 | \n", "0.1043 | \n", "0.04 | \n", "
1 | \n", "4 | \n", "41.0882 | \n", "7.0933 | \n", "30.16 | \n", "-0.0659 | \n", "0.0746 | \n", "0.04 | \n", "
2 | \n", "5 | \n", "41.0113 | \n", "7.0608 | \n", "30.36 | \n", "0.0855 | \n", "0.0980 | \n", "0.04 | \n", "
3 | \n", "6 | \n", "41.0608 | \n", "7.1048 | \n", "30.60 | \n", "0.0104 | \n", "0.1294 | \n", "0.04 | \n", "
4 | \n", "7 | \n", "41.0816 | \n", "7.0902 | \n", "30.68 | \n", "-0.0945 | \n", "0.0432 | \n", "0.04 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
12092 | \n", "1856 | \n", "41.0789 | \n", "6.6456 | \n", "794.88 | \n", "-0.0431 | \n", "0.0354 | \n", "0.04 | \n", "
12093 | \n", "1856 | \n", "41.0358 | \n", "6.6810 | \n", "794.92 | \n", "0.0290 | \n", "-0.0924 | \n", "0.04 | \n", "
12094 | \n", "1856 | \n", "41.0648 | \n", "6.5886 | \n", "794.96 | \n", "-0.0611 | \n", "0.0485 | \n", "0.04 | \n", "
12095 | \n", "1856 | \n", "41.0037 | \n", "6.6371 | \n", "795.00 | \n", "0.0998 | \n", "-0.0704 | \n", "0.04 | \n", "
12096 | \n", "1856 | \n", "41.1035 | \n", "6.5667 | \n", "795.04 | \n", "-0.0335 | \n", "0.0785 | \n", "0.04 | \n", "
12097 rows × 7 columns
\n", "\n", " | x | \n", "y | \n", "t | \n", "
---|---|---|---|
0 | \n", "26.6615 | \n", "39.5796 | \n", "0.06 | \n", "
1 | \n", "26.1820 | \n", "43.4160 | \n", "0.06 | \n", "
2 | \n", "27.0411 | \n", "26.9305 | \n", "0.06 | \n", "
3 | \n", "29.1381 | \n", "48.5524 | \n", "0.06 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
33547 | \n", "55.8001 | \n", "45.0347 | \n", "31.20 | \n", "
33548 | \n", "59.9244 | \n", "36.4617 | \n", "31.20 | \n", "
33549 | \n", "58.5234 | \n", "29.2296 | \n", "31.20 | \n", "
33550 | \n", "58.7866 | \n", "36.8735 | \n", "31.20 | \n", "
33551 rows × 3 columns
\n", "\n", " | n | \n", "x | \n", "y | \n", "t | \n", "
---|---|---|---|---|
0 | \n", "1 | \n", "26.1820 | \n", "43.4160 | \n", "0.06 | \n", "
1 | \n", "1 | \n", "26.2917 | \n", "43.2076 | \n", "0.12 | \n", "
2 | \n", "2 | \n", "27.0411 | \n", "26.9305 | \n", "0.06 | \n", "
3 | \n", "2 | \n", "27.3263 | \n", "26.7477 | \n", "0.12 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
12851 | \n", "5098 | \n", "47.0593 | \n", "36.7691 | \n", "31.14 | \n", "
12852 | \n", "5098 | \n", "47.3644 | \n", "36.9945 | \n", "31.20 | \n", "
12853 | \n", "5099 | \n", "36.9425 | \n", "36.9245 | \n", "31.14 | \n", "
12854 | \n", "5099 | \n", "36.7721 | \n", "37.0181 | \n", "31.20 | \n", "
12855 rows × 4 columns
\n", "\n", " | n | \n", "x | \n", "y | \n", "t | \n", "
---|---|---|---|---|
0 | \n", "1 | \n", "26.1820 | \n", "43.4160 | \n", "0.06 | \n", "
1 | \n", "1 | \n", "26.2917 | \n", "43.2076 | \n", "0.12 | \n", "
2 | \n", "2 | \n", "27.0411 | \n", "26.9305 | \n", "0.06 | \n", "
3 | \n", "2 | \n", "27.3263 | \n", "26.7477 | \n", "0.12 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
12851 | \n", "5098 | \n", "47.0593 | \n", "36.7691 | \n", "31.14 | \n", "
12852 | \n", "5098 | \n", "47.3644 | \n", "36.9945 | \n", "31.20 | \n", "
12853 | \n", "5099 | \n", "36.9425 | \n", "36.9245 | \n", "31.14 | \n", "
12854 | \n", "5099 | \n", "36.7721 | \n", "37.0181 | \n", "31.20 | \n", "
12855 rows × 4 columns
\n", "\n", " | n | \n", "x | \n", "y | \n", "t | \n", "
---|---|---|---|---|
0 | \n", "1 | \n", "26.1820 | \n", "43.4160 | \n", "0.06 | \n", "
1 | \n", "1 | \n", "26.2917 | \n", "43.2076 | \n", "0.12 | \n", "
2 | \n", "2 | \n", "27.0411 | \n", "26.9305 | \n", "0.06 | \n", "
3 | \n", "2 | \n", "27.3263 | \n", "26.7477 | \n", "0.12 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
12851 | \n", "5098 | \n", "47.0593 | \n", "36.7691 | \n", "31.14 | \n", "
12852 | \n", "5098 | \n", "47.3644 | \n", "36.9945 | \n", "31.20 | \n", "
12853 | \n", "5099 | \n", "36.9425 | \n", "36.9245 | \n", "31.14 | \n", "
12854 | \n", "5099 | \n", "36.7721 | \n", "37.0181 | \n", "31.20 | \n", "
12855 rows × 4 columns
\n", "\n", " | n | \n", "x | \n", "y | \n", "t | \n", "
---|---|---|---|---|
min | \n", "1.0 | \n", "19.8098 | \n", "19.2550 | \n", "0.06 | \n", "
max | \n", "5099.0 | \n", "61.5214 | \n", "58.6531 | \n", "31.20 | \n", "
\n", " | n | \n", "x | \n", "y | \n", "t | \n", "dx | \n", "dy | \n", "dt | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "3 | \n", "27.0411 | \n", "26.9305 | \n", "0.06 | \n", "0.2852 | \n", "-0.1828 | \n", "0.06 | \n", "
1 | \n", "3 | \n", "27.3263 | \n", "26.7477 | \n", "0.12 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
2 | \n", "4 | \n", "27.2278 | \n", "26.7087 | \n", "0.24 | \n", "0.1957 | \n", "-0.1466 | \n", "0.06 | \n", "
3 | \n", "4 | \n", "27.4235 | \n", "26.5621 | \n", "0.30 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
95 | \n", "47 | \n", "27.0603 | \n", "28.2362 | \n", "29.34 | \n", "-0.0411 | \n", "0.2687 | \n", "0.06 | \n", "
96 | \n", "47 | \n", "27.0192 | \n", "28.5049 | \n", "29.40 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
97 | \n", "48 | \n", "22.5607 | \n", "28.6995 | \n", "30.12 | \n", "0.0184 | \n", "0.0718 | \n", "0.06 | \n", "
98 | \n", "48 | \n", "22.5791 | \n", "28.7713 | \n", "30.18 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
99 rows × 7 columns
\n", "\n", " | n | \n", "x | \n", "y | \n", "t | \n", "dx | \n", "dy | \n", "dt | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "3 | \n", "27.0411 | \n", "26.9305 | \n", "0.06 | \n", "0.2852 | \n", "-0.1828 | \n", "0.06 | \n", "
1 | \n", "4 | \n", "27.2278 | \n", "26.7087 | \n", "0.24 | \n", "0.1957 | \n", "-0.1466 | \n", "0.06 | \n", "
2 | \n", "6 | \n", "25.1349 | \n", "23.8702 | \n", "1.56 | \n", "0.1845 | \n", "0.0494 | \n", "0.06 | \n", "
3 | \n", "7 | \n", "24.7621 | \n", "27.4019 | \n", "1.62 | \n", "-0.1749 | \n", "0.1544 | \n", "0.06 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
49 | \n", "46 | \n", "24.5129 | \n", "25.5778 | \n", "28.56 | \n", "-0.0652 | \n", "-0.0410 | \n", "0.06 | \n", "
50 | \n", "46 | \n", "24.4477 | \n", "25.5368 | \n", "28.62 | \n", "0.1256 | \n", "0.0381 | \n", "0.06 | \n", "
51 | \n", "47 | \n", "27.0603 | \n", "28.2362 | \n", "29.34 | \n", "-0.0411 | \n", "0.2687 | \n", "0.06 | \n", "
52 | \n", "48 | \n", "22.5607 | \n", "28.6995 | \n", "30.12 | \n", "0.0184 | \n", "0.0718 | \n", "0.06 | \n", "
53 rows × 7 columns
\n", "\n", " | n | \n", "
---|---|
0 | \n", "10 | \n", "
1 | \n", "61 | \n", "
2 | \n", "10 | \n", "
3 | \n", "10 | \n", "
... | \n", "... | \n", "
141 | \n", "44 | \n", "
146 | \n", "10 | \n", "
147 | \n", "16 | \n", "
148 | \n", "10 | \n", "
114 rows × 1 columns
\n", "\n", " | n | \n", "
---|---|
0 | \n", "10 | \n", "
1 | \n", "61 | \n", "
2 | \n", "10 | \n", "
3 | \n", "10 | \n", "
... | \n", "... | \n", "
146 | \n", "10 | \n", "
147 | \n", "16 | \n", "
148 | \n", "10 | \n", "
149 | \n", "0 | \n", "
150 rows × 1 columns
\n", "\n", " | n | \n", "
---|---|
0 | \n", "10 | \n", "
1 | \n", "61 | \n", "
2 | \n", "10 | \n", "
3 | \n", "10 | \n", "
... | \n", "... | \n", "
141 | \n", "44 | \n", "
146 | \n", "10 | \n", "
147 | \n", "16 | \n", "
148 | \n", "10 | \n", "
114 rows × 1 columns
\n", "\n", " | n | \n", "
---|---|
0 | \n", "10 | \n", "
1 | \n", "61 | \n", "
2 | \n", "10 | \n", "
3 | \n", "10 | \n", "
... | \n", "... | \n", "
141 | \n", "44 | \n", "
146 | \n", "10 | \n", "
147 | \n", "16 | \n", "
148 | \n", "10 | \n", "
114 rows × 1 columns
\n", "\n", " | mean trajectory length | \n", "
---|---|
4 | \n", "6.000000 | \n", "
11 | \n", "3.666667 | \n", "
12 | \n", "3.000000 | \n", "
17 | \n", "6.272727 | \n", "
... | \n", "... | \n", "
154 | \n", "10.000000 | \n", "
155 | \n", "9.200000 | \n", "
159 | \n", "6.400000 | \n", "
160 | \n", "10.666667 | \n", "
87 rows × 1 columns
\n", "