Skip to main content
. 2016 Feb 2;3(1):ENEURO.0095-15.2015. doi: 10.1523/ENEURO.0095-15.2015

Table 6.

MATLAB code for finding burst-pause patterns using RGS output

function [BSPB, BDPB] = BurstPausePatternDetector(Bursts,Pauses,dt)
%% BURSTPAUSEPATTERNDETECTOR help
%
% Identifies patterns in bursting and pausing using outputs from
% RGSDetect.
%
% INPUTS:
% Bursts: Structure containing burst information obtained from RGSDetect.
% Pauses: Structure containing pause information obtained from RGSDetect.
% dt: Minimum threshold connecting burst and pause events. Argument can
% take single threshold or vector of thresholds.
%
% OUTPUTS:
% NOTE: Each structure element of both outputs have L cells containing
% NxM matrices, where L is the length of vector dt, N is the number
% of hits and M is the length of the pattern. Each element of the cell
% contains the results of its respective threshold in dt.
% NOTE: Thresholds dynamically attenuated so they do not fall past
% more than one event.
%
% BSPB: Structure containing patterns associated with string pauses.
% BSPB.BSPHits (s): Cell of 2 column matrices. The matrices
% contain string pauses falling within the threshold past bursts.
% Each row is one pattern where the first column contains burst
% start times, and the second column contains pause start times.
% BSPB.SPBHits (s): Cell of 2 column matrices. The matrices
% contain bursts falling within the threshold past string pauses.
% Each row is one pattern where the first column contains string
% pause start times, and the second column contains burst start times.
% BSPB.BSPBHits (s): Cell of 3 column matrices. The matrices
% contain bursts falling within the threshold past string pauses.
% Each row is one pattern where the first column contains string
% pause start times, and the second column contains burst start times.
% BDPB: Structure containing patterns associated with discrete
% pauses.
% BDPB.BDPHits (s): Cell of 2 column matrices. The matrices
% contain discrete pauses falling within the threshold past bursts.
% Each row is one pattern where the first column contains burst
% start times, and the second column contains pause start times.
% BDPB.DPBHits (s): Cell of 2 column matrices. The matrices
% contain bursts falling within the threshold past discrete pauses.
% Each row is one pattern where the first column contains
% discrete pause start times, and the second column contains
% burst start times.
% BDPB.BDPBHits (s): Cell of 3 column matrices. The matrices
% contain bursts falling within the threshold past discrete pauses.
% Each row is one pattern where the first column contains
% discrete pause start times, and the second column contains
% burst start times.
%
% EXAMPLE values used in this paper:
% Spikes = (Spike times go here);
% N_min = 2;
% Steps = -3:0.005:1.5;
% p = 0.05;
% alpha = 0.05;
% [Bursts, Pauses] = RGSDetect(Spikes, N_min, Steps, p, alpha);
% dt = [3 6 9 12 15 18 21];
% [BSPB, BDPB] = BurstPausePatternDetector(Bursts,Pauses,dt);
%
%% Initialization
BWindows = Bursts.Windows;
BurstStarts = BWindows(:,1);
BurstEnds = BWindows(:,2);
PWindows = Pauses.Windows;
PauseStarts = PWindows(:,1);
PauseEnds = PWindows(:,2);
DPStarts = Pauses.AllSpikes;
DPEnds = Pauses.AllSpikes + Pauses.AllLengths;
%% **Burst-String Pause-Burst** Search
%B-SP Sub-search
BSPHits = cell(length(dt),1);
for i = 1:length(dt)
%Add threshold to end of all burst events.
edges = [BurstEnds BurstEnds+dt(i)/60]';
edges = edges(:)';
%Fix ranges that overlap.
edges(diff(edges) <= 0) = edges(logical([0 diff(edges)<=0])) - 10^(-8);
%Histogram count the string pauses using ranges (edges).
[N,∼,bin] = histcounts(PauseStarts,edges);
%Take only the first string pause after each burst.
bin(logical([0;diff(bin) == 0]')) = 0;
%Use the results from even bins.
bin(mod(bin,2) == 0) = 0;
bin(bin ∼= 0) = 1;
N(2:2:end) = [];
%Assign results to BSPHits.
BSPHits(i) = {[BurstStarts(N∼=0) PauseStarts(logical(bin))]};
end
BSPB.BSPHits = BSPHits;
%SP-B Sub-search
SPBHits = cell(length(dt),1);
for i = 1:length(dt)
edges = [PauseEnds PauseEnds+dt(i)/60]';
edges = edges(:)';
edges(diff(edges) <= 0) = edges(logical([0 diff(edges)<=0])) - 10^(-8);
[N,∼,bin] = histcounts(BurstStarts,edges);
bin(logical([0;diff(bin) == 0]')) = 0;
bin(mod(bin,2) == 0) = 0;
bin(bin ∼= 0) = 1;
N(2:2:end) = [];
SPBHits(i) = {[PauseStarts(N∼=0) BurstStarts(logical(bin))]};
end
BSPB.SPBHits = SPBHits;
%B-SP-B Concatenation
BSPBHits = cell(length(dt),1);
for i = 1:length(dt)
%Obtain results from BSP and SPB
BSPi = BSPHits{i}; SPBi = SPBHits{i};
%Find common start times of string pauses.
[hits,ia,ib] = intersect(BSPi(:,2),SPBi(:,1));
%Concatenate the common BSP and SPB patterns into a 3 event pattern.
BSPBHits(i) = {[BSPi(ia,1) hits SPBi(ib,2)]};
end
BSPB.BSPBHits = BSPBHits;
%% **Burst-Discrete Pause-Burst** Search
%B-DP Sub-search
BDPHits = cell(length(dt),1);
for i = 1:length(dt)
edges = [BurstEnds BurstEnds+dt(i)/60]';
edges = edges(:)';
edges(diff(edges) <= 0) = edges(logical([0 diff(edges)<=0])) - 10^(-8);
[N,∼,bin] = histcounts(DPStarts,edges);
bin(logical([0;diff(bin) == 0]')) = 0;
bin(mod(bin,2) == 0) = 0;
bin(bin ∼= 0) = 1;
N(2:2:end) = [];
BDPHits(i) = {[BurstStarts(N∼=0) DPStarts(logical(bin))]};
end
BDPB.BDPHits = BDPHits;
%DP-B Sub-search
DPBHits = cell(length(dt),1);
for i = 1:length(dt)
edges = [DPEnds DPEnds+dt(i)/60]';
edges = edges(:)';
edges(diff(edges) <= 0) = edges(logical([0 diff(edges)<=0])) - 10^(-8);
[N,∼,bin] = histcounts(BurstStarts,edges);
bin(logical([0;diff(bin) == 0]')) = 0;
bin(mod(bin,2) == 0) = 0;
bin(bin ∼= 0) = 1;
N(2:2:end) = [];
DPBHits(i) = {[DPStarts(N∼=0) BurstStarts(logical(bin))]};
end
BDPB.DPBHits = DPBHits;
%B-DP-B Concatenation
BDPBHits = cell(length(dt),1);
for i = 1:length(dt)
BDPi = BDPHits{i}; DPBi = DPBHits{i};
[hits,ia,ib] = intersect(BDPi(:,2),DPBi(:,1));
BDPBHits(i) = {[BDPi(ia,1) hits DPBi(ib,2)]};
end
BDPB.BDPBHits = BDPBHits;
end