MATLAB scripts to plot data from a fiber photometry recording.
- MATLAB (last tested with R2022a)
- Install MATLAB with the following toolboxes:
- Curve Fitting Toolbox
- Signal Processing Toolbox
- Statistics and Machine Learning Toolbox
- Download and extract these scripts to Documents/MATLAB folder.
- Run
setup.m
to add FPA dependencies to the MATLAB search path. - See and edit examples according to your experimental setup.
fpa = FPA(time, signal, reference, configuration);
fpa.plot();
The GUI is under development and has limitted functionality compared to the script.
GUI();
Remove baseline from data, correct from motion artifacts; normalize, filter, and detect peaks of spontaneous activity in user defined epochs.
Processing steps:
- Resample data to a given frequency.
- Replace artifacts with linear interpolation in flagged regions.
- Baseline correction modeled as an exponential decay of the low-pass filtered data.
- Correct for motion artifacts by subtracting reference to signal, after a polynomial fit.
- Remove fast oscillations with a low-pass filter.
- Normalize data as df/f or z-score according to settings.
- Find peaks of spontaneous activity in low-pass filtered data.
- Figure 1:
- Raw signal and reference, and baseline model.
- Baseline corrected signal and reference.
- Motion correction.
- Normalization.
- Peaks.
- Figure 2:
- Power spectrum for each epoch.
- Figure 3:
- Boxplot.
- Remaining figures:
- Peak triggers, event-triggers, epoch start-triggers, and epoch stop-triggers.
- Triggered average of peaks (if any), event-triggers, epoch start, and epoch stop.
configuration
is a struct with the following fields (defaults are used for missing fields):
conditionEpochs
- Epochs for different conditions:{'epoch1', [start1, end1, start2, end2, ...], 'epoch2', ...}
baselineEpochs
- Time epochs (s) to include for baseline correction.thresholdEpochs
baselineLowpassFrequency
- Frequency representative of baseline.airPLS
- Baseline correction for all data using airPLS (true, false, or airPLS inputs).artifactEpochs
- Time epochs (s) to remove.resamplingFrequency
- Resampling frequency (Hz).lowpassFrequency
- Lowest frequency permitted in normalized signal.peaksLowpassFrequency
- Lowest frequency to detect peaks.triggeredWindow
- Length of time to capture around each peak of spontaneous activity.fitReference
- Shift and scale reference to fit signal.
Also see normalization and thresholding configurations below.
See source code for default values:
edit('FPA');
Units for time and frequency are seconds and hertz respectively.
Normalization is calculated as (f - f0) / f1
where f0
and f1
can be data provided by the user or calculated using given functions:
configuration.f0 = @mean;
configuration.f1 = @mean;
configuration.f0 = @mean;
configuration.f1 = @std;
configuration.f0 = @median;
configuration.f1 = @mad;
configuration.f0 = @median;
configuration.f1 = @std;
epochs = [0, 100, 500, 550, 1000, Inf]
configuration.f0 = {@mean, epochs};
configuration.f1 = {@mean, epochs};
window = 60;
configuration.f0 = {@movmean, window};
configuration.f1 = {@movmean, window};
[further combinations possible with @movmean
, @movmedian
, @movstd
, @movmad
, @mov
...].
f0 = ones(size(time));
f1 = ones(size(time)) * 10;
configuration.f0 = f0;
configuration.f1 = f1;
Fluorescence deflections are considered peaks when they exceed a threshold calculated as k * f2 + f3
and they are provided by the user as configuration.threshold = {k, f2, f3}
configuration.threshold = {2.91, @mad, @median}
configuration.threshold = {2.91, @mad, 0}
configuration.threshold = {2.00, @std, @mean}
[data, names] = loadData(filename)
Returns a data
matrix where columns correspond to channels listed in names
, that is, time followed by other data columns.
Expected format #1:
time | name 1 | name 2 | ... | name N |
---|---|---|---|---|
t1 | a1 | b2 | ... | zN |
... | ... | .... | ... | ... |
tM | aM | bM | ... | zM |
Expected format #2:
name 1 | name 2 | ... | name N | |
---|---|---|---|---|
time | accepted|rejected | accepted|rejected | ... | accepted|rejected |
t1 | a1 | b2 | ... | zN |
... | ... | .... | ... | ... |
tM | aM | bM | ... | zM |
[data, names, sheetName] = loadData(filename, <sheetNumber|sheetName>)
Returns a data
matrix where columns correspond to channels listed in names
. A sheet number or a sheet name can be passed as the second parameter (default is the first sheet in the document). The sheet name is also returned.
Expected format for each sheed in a document:
time | name 1 | name 2 | ... | name N |
---|---|---|---|---|
t1 | a1 | b2 | ... | zN |
... | ... | .... | ... | ... |
tM | aM | bM | ... | zM |
[data, units, names] = loadABF(filename)
[data, names] = loadTDT(folder)
Parses a project folder stored by a TDT DAQ and returns a data
matrix where columns correspond to channels listed in names
.
[time, data, units, names, comments] = loadLabChart(filename)
Loads a mat
file exported by LabChart in an intuitive manner.
[time, data, units, names] = loadAdicht(filename)
Loads an aditch
file.
Data are organized in 2D cells where row indices select channels and column indices select blocks:
time{channel, block}
data{channel, block}
Units are organized in a cell array where row indices select channels and column indices select blocks:
- Data units:
units{channel, block}
Channel names are organized in a cell array:
names{channel}
ttl = loadInscopixTTL(filename)
Returns timestamps where pin IO1
changes from low to high state.
[labels, start, finish, distance, speed] = loadCleverSys(filename, <sheet>)
epochs = loadCleverSys(filename, <sheet>)
Returns a list of event epochs generated by CleverSys.
[labels, start, stop] = loadBoris(filename)
epochs = loadBoris(filename)
Returns a list of event epochs scored with BORIS.
See Changelog
© 2018 Leonardo Molina
This project is licensed under the GNU GPLv3 License.