Skip to content

Commit

Permalink
add CTX, remove try catch
Browse files Browse the repository at this point in the history
better to fix errors than have such large try catches
  • Loading branch information
ryanharvey1 committed Dec 6, 2024
1 parent 51c69b9 commit 328b3b5
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions lfp/detect_delta_waves.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function detect_delta_waves(varargin)
addParameter(p, 'channel', [], @isnumeric);
addParameter(p, 'peak_to_trough_ratio', 3, @isnumeric); % legacy name for "threshold"
addParameter(p, 'threshold', 3, @isnumeric);
addParameter(p, 'brainRegion', {'PFC', 'MEC', 'LEC', 'EC', 'ILA', 'PL', 'Cortex'}, @(x) any(iscell(x), iscchar(x)));
addParameter(p, 'brainRegion', {'PFC', 'MEC', 'LEC', 'EC', 'ILA', 'PL', 'Cortex', 'CTX'}, @(x) any(iscell(x), iscchar(x)));
addParameter(p, 'manual_pick_channel', false, @islogical);
addParameter(p, 'use_sleep_score_delta_channel', false, @islogical);
addParameter(p, 'EMG_threshold', 0.6, @isnumeric);
Expand Down Expand Up @@ -281,7 +281,7 @@ function run(basepath, p)
immobility = EMG.timestamps(FindInterval(EMG.data < EMG_threshold));
immobility(diff(immobility, [], 2) < 1, :) = [];
% reshape interval if needed
if size(immobility,2) == 1
if size(immobility, 2) == 1
immobility = immobility';
end
else
Expand All @@ -303,48 +303,48 @@ function run(basepath, p)

if verify_firing
% Verify that spiking decreases at the peak of the delta
try
[~, st] = importSpikes('basepath', basepath, 'brainRegion', brainRegion);
if ~st.isempty
[delta_psth, ts] = PETH(st.spikes, deltas(:, 2));
% smooth delta psth
delta_psth_smooth = delta_psth;
delta_psth_smooth = nanzscore(Smooth(delta_psth_smooth, [0, 1]), [], 2);
% extract delta response
response = mean(delta_psth_smooth(:, InIntervals(ts, [-1, 1]*0.05)), 2);
% sort responses and locate when value passes threshold
ordered = sortrows([deltas(:, 5) - deltas(:, 6), response], -1);
threshold = ordered(find(Smooth(ordered(:, 2), 100) <= -0.5, 1, 'last'), 1);
% only keep deltas with sufficient response
[~, st] = importSpikes('basepath', basepath, 'brainRegion', brainRegion);
if ~st.isempty
[delta_psth, ts] = PETH(st.spikes, deltas(:, 2));
% smooth delta psth
delta_psth_smooth = delta_psth;
delta_psth_smooth = nanzscore(Smooth(delta_psth_smooth, [0, 1]), [], 2);
% extract delta response
response = mean(delta_psth_smooth(:, InIntervals(ts, [-1, 1]*0.05)), 2);
% sort responses and locate when value passes threshold
ordered = sortrows([deltas(:, 5) - deltas(:, 6), response], -1);
threshold = ordered(find(Smooth(ordered(:, 2), 100) <= -0.5, 1, 'last'), 1);
% only keep deltas with sufficient response
if ~isempty(threshold)
deltas = deltas(deltas(:, 5)-deltas(:, 6) > threshold, :);
% verify that the dip in firing around delta
delta_psth_avg = mean(delta_psth);
if mean(delta_psth_avg) < mean(delta_psth_avg(ts > -0.1 & ts < 0.1))
warning("Firing rate does not dip around delta, change paramaters")
figure;
subplot(2, 1, 1)
plot(ts, delta_psth_avg)
subplot(2, 1, 2)
PlotColorMap(Shrink(sortby(delta_psth, -(deltas(:, 5) - deltas(:, 6))), 72, 1), 'x', ts);
colormap("parula")
keyboard
end
% Optionally, view the firing around the detected events
if showfig
figure;
subplot(2, 1, 1)
plot(ts, delta_psth_avg)
subplot(2, 1, 2)
PlotColorMap(Shrink(sortby(delta_psth, -(deltas(:, 5) - deltas(:, 6))), 72, 1), 'x', ts);
colormap("parula")
end
else
warning('impossible to verify firing')
verify_firing = false;
warning("no cortical cells, impossible to verify firing");
end
catch
% verify that the dip in firing around delta
delta_psth_avg = mean(delta_psth);
if mean(delta_psth_avg) < mean(delta_psth_avg(ts > -0.1 & ts < 0.1))
warning("Firing rate does not dip around delta, change paramaters")
figure;
subplot(2, 1, 1)
plot(ts, delta_psth_avg)
subplot(2, 1, 2)
PlotColorMap(Shrink(sortby(delta_psth, -(deltas(:, 5) - deltas(:, 6))), 72, 1), 'x', ts);
colormap("parula")
keyboard
end
% Optionally, view the firing around the detected events
if showfig
figure;
subplot(2, 1, 1)
plot(ts, delta_psth_avg)
subplot(2, 1, 2)
PlotColorMap(Shrink(sortby(delta_psth, -(deltas(:, 5) - deltas(:, 6))), 72, 1), 'x', ts);
colormap("parula")
end
else
verify_firing = false;
warning("problem loading cortical cell spiking, impossible to verify firing");
warning("no cortical cells, impossible to verify firing");
end
end

Expand Down

0 comments on commit 328b3b5

Please sign in to comment.