Skip to content

Commit 63b1acb

Browse files
Adding dentate spike and CSD analysis
1 parent 13ca6e9 commit 63b1acb

29 files changed

+482
-0
lines changed

Filters/ejdsfilter4.mat

978 Bytes
Binary file not shown.

Rest Analysis/DSMUA.m

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
function out = DSMUA(index, excludeperiods, mua, dspikes, chinfo, varargin)
2+
%parse the options
3+
win = [-0.4 0.4];
4+
binsize = 0.1;
5+
6+
Fs = 1000;
7+
spikeFs = 30000;
8+
9+
for option = 1:2:length(varargin)-1
10+
if ischar(varargin{option})
11+
switch(varargin{option})
12+
case 'event_window'
13+
win = varargin{option+1};
14+
case 'binsize'
15+
binsize = varargin{option+1};
16+
case 'trig'
17+
trigcrit = varargin{option+1};
18+
case 'probe'
19+
probecrit = varargin{option+1};
20+
otherwise
21+
error(['Option ',varargin{option},' unknown.']);
22+
end
23+
else
24+
error('Options must be strings, followed by the variable');
25+
end
26+
end
27+
28+
% search through chinfo struct to find channels meeting trig and probe criteria
29+
trigindex = evaluatefilter(chinfo,trigcrit);
30+
probeindex = evaluatefilter(chinfo,probecrit) ;
31+
out.trigindex = trigindex;
32+
out.probeindex = probeindex;
33+
34+
fulltimes = mua{trigindex(1,1)}{trigindex(1,2)}{trigindex(1,3)}.starttime:1/Fs:mua{trigindex(1,1)}{trigindex(1,2)}{trigindex(1,3)}.endtime;
35+
validtimes = ~isExcluded(fulltimes, excludeperiods);
36+
37+
%iterate over trigger channels
38+
for t = 1:size(trigindex,1)
39+
40+
%get dspike trigger times
41+
d = dspikes{trigindex(t,1)}{trigindex(t,2)}{trigindex(t,3)};
42+
valid = find(~isExcluded(d.starttime,excludeperiods) & ~isExcluded(d.endtime,excludeperiods));
43+
44+
d.starttime = d.starttime(valid);
45+
d.endtime = d.endtime(valid);
46+
d.peaktime = mua{trigindex(1,1)}{trigindex(1,2)}{trigindex(1,3)}.starttime + d.peakind / Fs;
47+
triggers = d.peaktime(valid);
48+
out.dstimes{t} = triggers;
49+
50+
%iterate through probe channels
51+
for p = 1:size(probeindex,1)
52+
pmua = mua{probeindex(p,1)}{probeindex(p,2)}{probeindex(p,3)};
53+
spiketimes = pmua.spiketimes/spikeFs;
54+
bins = fulltimes(1):binsize:fulltimes(end);
55+
validinds = ~isExcluded(spiketimes,excludeperiods);
56+
57+
bininds = ~isExcluded(bins,excludeperiods);
58+
out.baserate{t}{p} = sum(validinds)/sum(validtimes)*Fs; %FR over all immob
59+
out.sdbaserate{t}{p} = std(histcounts(spiketimes(validinds),bins(bininds))/binsize);
60+
61+
bins = win(1):binsize:win(2);
62+
out.psth{t}{p} = NaN(length(triggers),(length(bins)-1)); %no 10x
63+
out.peakrate{t}{p} = NaN(length(triggers),1);
64+
out.DSrate{t}{p} = NaN(length(triggers),1);
65+
out.normrate{t}{p} = NaN(length(triggers),1);
66+
67+
%iterate over dspikes
68+
for r = 1:length(triggers)
69+
bins = win(1)+triggers(r):binsize:triggers(r)+win(2); %binsize
70+
out.psth{t}{p}(r,:) = histcounts(spiketimes,bins)/binsize; %binsize
71+
out.peakrate{t}{p}(r) = length(spiketimes(spiketimes>triggers(r) & spiketimes<triggers(r)+binsize))/binsize;
72+
out.DSrate{t}{p}(r) = length(spiketimes(spiketimes>d.starttime(r) & spiketimes<d.endtime(r)))/(d.endtime(r) - d.starttime(r));
73+
out.normrate{t}{p}(r) = (out.DSrate{t}{p}(r)-out.baserate{t}{p})/out.sdbaserate{t}{p}';
74+
end
75+
end
76+
end

Rest Analysis/DSdescript.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function out = DSdescript(index, excludeperiods, dspikes, eeg, chinfo, varargin)
2+
% out = ripdescript(index, excludeperiods, ripples, options)
3+
% Computes basic characteristics of detected ripple events
4+
5+
for option = 1:2:length(varargin)-1
6+
if ischar(varargin{option})
7+
switch(varargin{option})
8+
case 'trig'
9+
trigcrit = varargin{option+1};
10+
otherwise
11+
error(['Option ',varargin{option},' unknown.']);
12+
end
13+
else
14+
error('Options must be strings, followed by the variable');
15+
end
16+
end
17+
18+
%open dspikes
19+
trigindex = evaluatefilter(chinfo,trigcrit);
20+
out.trigindex = trigindex;
21+
d = dspikes{trigindex(1,1)}{trigindex(1,2)}{trigindex(1,3)};
22+
e = eeg{trigindex(1,1)}{trigindex(1,2)}{trigindex(1,3)};
23+
valid = find(~isExcluded(d.starttime,excludeperiods) & ~isExcluded(d.endtime,excludeperiods));
24+
25+
%calculate DS rate in 1min bins
26+
Fs = e.samprate;
27+
fulltimes = e.starttime:1/Fs:e.endtime;
28+
validtimeinds = find(~isExcluded(fulltimes, excludeperiods));
29+
timeseq = [validtimeinds(1:60000:end); validtimeinds(end)];
30+
timecounts = histcounts(d.startind(valid),timeseq)/60; %rips per 1min bin
31+
32+
out.dspeakamps = d.peak(valid);
33+
out.dslength = d.endind(valid) - d.startind(valid); %in ms
34+
out.timecounts = timecounts;

Rest Analysis/RTCSD.m

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
function out = RTCSD(index, excludeperiods, eeg, ripples, chinfo, varargin)
2+
%parse the options
3+
win = [-0.2 0.2];
4+
minstd = 5;
5+
interripwin = 0; %does not eliminate ripples that occur in doublets or triplets
6+
Fs = 1000;
7+
8+
for option = 1:2:length(varargin)-1
9+
if ischar(varargin{option})
10+
switch(varargin{option})
11+
case 'win'
12+
win = varargin{option+1};
13+
case 'minstd'
14+
minstd = varargin{option+1};
15+
case 'trig'
16+
trigcrit = varargin{option+1};
17+
case 'freqband'
18+
freqs = varargin{option+1};
19+
otherwise
20+
error(['Option ',varargin{option},' unknown.']);
21+
end
22+
else
23+
error('Options must be strings, followed by the variable');
24+
end
25+
end
26+
27+
out.win = win;
28+
29+
% search through chinfo struct to find channels meeting trig criteria
30+
trigindex = evaluatefilter(chinfo,trigcrit);
31+
out.trigindex = trigindex;
32+
33+
%get EEG & rest times
34+
epoch_eeg = eeg{trigindex(1,1)}{trigindex(1,2)};
35+
Fs_temp = length(epoch_eeg{1}.data)/(epoch_eeg{1}.endtime-epoch_eeg{1}.starttime);
36+
fulltimes = epoch_eeg{1}.starttime:1/Fs_temp:epoch_eeg{1}.endtime;
37+
validtimes = ~isExcluded(fulltimes, excludeperiods);
38+
39+
%if freq band specified, filter trace
40+
if exist('freqs','var')
41+
for i=1:length(epoch_eeg)
42+
coeff = designeegfilt(Fs,freqs(1),freqs(2));
43+
data = double(epoch_eeg{i}.data);
44+
epoch_eeg{i}.data = int16(filtfilt(coeff,1,data));
45+
end
46+
end
47+
48+
%smoothing via triangular kernel
49+
for i = 2:length(epoch_eeg)-1
50+
%smoothing via triangular kernel
51+
b = epoch_eeg{i}.data;
52+
a = epoch_eeg{i-1}.data;
53+
c = epoch_eeg{i+1}.data;
54+
smooth_eeg{i}.data = (a+2*b+c)/4;
55+
end
56+
%second spatial derivative
57+
csd = NaN(length(epoch_eeg),length(epoch_eeg{1}.data)); %channels x time
58+
for i = 3:length(epoch_eeg)-2
59+
%smoothing via triangular kernel
60+
b = smooth_eeg{i}.data;
61+
a = smooth_eeg{i-1}.data;
62+
c = smooth_eeg{i+1}.data;
63+
csd(i,:) = (a-2*b+c)/4;
64+
end
65+
out.csd = csd;
66+
67+
%mean & SD over rest trace
68+
csd_base = csd(:,validtimes(1:length(csd)));
69+
out.baseline = mean(csd_base,2);
70+
out.sd = std(csd_base,0,2);
71+
72+
%get ripple trigger times
73+
rip = ripples{trigindex(1,1)}{trigindex(1,2)}{trigindex(1,3)};
74+
[valid, ~] = getvalidrips(ripples,index,trigindex, excludeperiods, win, minstd, interripwin);
75+
rip.starttime = rip.starttime(valid);
76+
rip.endtime = rip.endtime(valid);
77+
triggers = rip.threshind(valid);
78+
out.ripinds = triggers;
79+
80+
%bin by ripple triggers
81+
ripcsd = NaN(length(triggers),length(epoch_eeg),length(win(1):1/Fs:win(2))); %rips x channels x time
82+
for r = 1:length(triggers)
83+
ripcsd(r,:,:) = csd(:,win(1)*Fs+triggers(r):triggers(r)+win(2)*Fs);
84+
end
85+
out.ripcsd = ripcsd;
86+
87+
%calculate peaks
88+
out.peakripsource = max(ripcsd,[],3); %rips x channels
89+
out.peakripsink = min(ripcsd,[],3); %rips x channels
90+
91+
%Z-score
92+
out.zripsource = (out.peakripsource - out.baseline') ./ out.sd';
93+
out.zripsink = (out.peakripsink - out.baseline') ./ out.sd';
94+
95+
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)