Nondairy-Creamer / tmac

Package for removing motion artifacts from two-channel imaging
MIT License
8 stars 1 forks source link
behavior calcium imaging motion

Two-channel motion artifact correction (TMAC)

Installation:

Navigate to the python project directory

git clone https://github.com/Nondairy-Creamer/tmac
cd tmac
pip install -e .

General description:

For a full description please consult the paper: https://doi.org/10.1371/journal.pcbi.1010421

Modified from the Author Summary in the paper:

Optical imaging of neural activity using fluorescent indicators is a powerful technique for studying the brain, yet despite the widespread success of this technique many difficulties remain. Imaging moving animals can be challenging, because the animal’s movements may introduce changes in fluorescence intensity that are unrelated to neural activity, known as motion artifacts. We focus on the special case of two-channel imaging, where two indicators are present in the same cell: an activity-dependent indicator and an activity-independent indicator. This is the code for our Two-channel Motion Artifact Correction (TMAC) method. TMAC uses a generative model of the fluorescence to infer the latent neural activity without motion artifacts. A more intuitive description would be that this method simply subtracts the activity-independent channel from the activity-dependent channel while accounting for channel-independent noise.

Below we refer to the activity-depdendent channel as the "green channel" and the activity-independent channel as the "red channel" because it relates to the common use case where researchers measure calcium dependent GCaMP fluorescence of a red fluorophore and activity-independent fluoresence of a red fluorophore.

Importantly, TMAC will remove motion artifacts in any type of two-channel imaging, so long as one channel is activity-independent and both channels share the same motion artifact component. TMAC could therefore be applied to a wide range of two-channel imaging modalities including for voltage imaging, fiber photometry when using an isosbestic wavelength, or two-channel two-photon imaging.

Usage:

To see an example on synthetic data, install the package into a python project, then run the script examples/tmac_on_synthetic_data.py

The model can be called in a python project with the following commands, where red and green are numpy matricies of the red and green fluorescence data with dimensions [time, neurons].

import tmac.models as tm

trained_variables = tm.tmac_ac(red, green)

Also included are two preprocessing functions. A function to linearly interpolate over time to remove NaNs from the data and one to correct for photobleaching by dividing by an exponential with a single decay constant fit with all the neural data. TMAC assumes a constant mean and no NaNs, so adjustments like this are necessary preprocessing steps, though any method for data imputation and bleach correction will suffice. Using the preprocessing steps:

import tmac.models as tm
import tmac.preprocessing as tp

red_corrected = tp.photobleach_correction(red)
green_corrected = tp.photobleach_correction(green)

red_interp = tp.interpolate_over_nans(red_corrected)[0]
green_interp = tp.interpolate_over_nans(green_corrected)[0]

trained_variables = tm.tmac_ac(red_interp, green_interp)

Output:

The output dictionary contains

Notes

Assumptions and limitations