Skip to content

Commit

Permalink
adding some clusterless decoding code from kenny
Browse files Browse the repository at this point in the history
  • Loading branch information
droumis committed Nov 2, 2019
1 parent 3d6b06e commit 7a05997
Show file tree
Hide file tree
Showing 64 changed files with 36,268 additions and 383 deletions.
351 changes: 149 additions & 202 deletions DFAnalysis/dfa_reactivationPSTH.m

Large diffs are not rendered by default.

104 changes: 11 additions & 93 deletions DFFunctions/dfa_lickswrcorr.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@
end

pconf = paramconfig;

plotfigs = 1;
pausefigs = 0;
savefigs = 1;
savefigas = {'png'};

bin = .01;
tmax = 1;
boutNum = 10;
Expand Down Expand Up @@ -125,6 +119,9 @@
fprintf('lBurst swrs in valid ILI: %d (%.02f pct swrs) \n', sum(swrValidILI), ...
sum(swrValidILI)/length(swrStart)*100)
swrInBurstStart = swrInBurstStart(swrValidILI);
if isempty(swrInBurstStart)
return
end
swrBinILI = swrBinILI(swrValidILI);
swrTimeSinceLick = swrTimeSinceLick(swrValidILI);

Expand Down Expand Up @@ -228,18 +225,18 @@
swrInBurstStart = swrInBurstStart(swrValidILI);
swrBinILI = swrBinILI(swrValidILI);
swrTimeSinceLick = swrTimeSinceLick(swrValidILI);
% fprintf('swrs with valid ILI: %d (%.02f pct swrs) \n', numel(swrInBurstStart),...
% numel(swrInBurstStart)/length(swrStart)*100)
% fprintf('swrs with valid ILI: %d (%.02f pct swrs) \n', numel(swrInBurstStart),...
% numel(swrInBurstStart)/length(swrStart)*100)
% save burst start/end time for each enclosed and valid swr
[~,~,swrLickBurstIdx] = histcounts(swrInBurstStart, [burstIntvs(:,1); inf]);
swrBurstInterval = burstIntvs(swrLickBurstIdx,:);

out.swrBinILIShuf{end+1} = swrBinILI;
out.swrInBurstStartShuf{end+1} = swrInBurstStart;
out.swrTimeSinceLickShuf{end+1} = swrTimeSinceLick;
out.swrBurstIntervalShuf{end+1} = swrBurstInterval;

%% Compute shuffle lickDin x swr
%% Compute shuffle lickDin x swr
% xcorr norm smooth
xc = spikexcorr(sort(swrInBurstStart), lickboutlicks, bin, tmax);
normxc = xc.c1vsc2 ./ sqrt(xc.nspikes1 * xc.nspikes2); % normalize xc
Expand All @@ -254,7 +251,7 @@
p1 = xc.nspikes1/T;
p2 = xc.nspikes2/T; % fr in Hz
expProb = p1*p2; % per sec. Expected probability

out.xcShuf{end+1} = xc;
out.normxcShuf{end+1} = normxc;
out.smthxcShuf{end+1} = smthxc;
Expand Down Expand Up @@ -286,88 +283,8 @@
out.phasemodShuf{end+1} = phasemod;
end
end

%% plot
if plotfigs
[~, fname,~] = fileparts(mfilename('fullpath'));
outdir = sprintf('%s/%s/', pconf.andef{4},fname,animal);
Pp=load_plotting_params({'defaults','dfa_lickswrcorr'}, 'pausefigs', pausefigs, ...
'savefigs', savefigs);

%% Xcorr norm smooth, shuff mean/std
sf1 = subaxis(2,2,1,Pp.posparams{:});
sf1.Tag = 'xcorr';

% shuffled xcorr with std ghost trail
xmsh = mean(cell2mat(out.smthxcShuf'));
xstdsh = std(cell2mat(out.smthxcShuf')); %/size(cell2mat(out.smthxcShuf'),1);
plot(out.xc.time, xmsh, 'color', [0 0 1 .2], 'linewidth', 1);
hold on;
fill([out.xc.time'; flipud(out.time')],[xmsh'-xstdsh';flipud(xmsh'+xstdsh')],'b', 'linestyle', ...
'none', 'facealpha', .2);
% xcorr norm
bar(out.xc.time, out.normxc, 'k', 'facealpha', .2, 'edgealpha', 0)
% xcorr norm smooth
plot(out.time, out.smthxc, 'k')
line([0 0], ylim, 'color', 'k', 'linestyle', '--', 'linewidth', .5)

ylabel('xcorr');
xlabel('time from lick s');
% title('xcorr
hold off;
%% excorr over shuff excorr cdf distr
% relative swr from last lick
sf2 = subaxis(2,2,2);
histogram(cell2mat(out.excorrShuf), 60,'Normalization','probability','edgealpha', 0, 'facecolor', 'k');
excsort = sort(cell2mat(out.excorrShuf));
idxsig = round(sigpct*length(out.excorrShuf));
line([excsort(idxsig) excsort(idxsig)], ylim, 'color', [0 0 0 .8], 'linestyle', '--');
hold on;
line([out.excorr out.excorr], ylim, 'color', 'r');
excp = 1-sum(out.excorr>cell2mat(out.excorrShuf))/length(out.excorrShuf);
title(sprintf('excorr %.03f p%.03f', out.excorr, excp));
ylabel('probability')
xlabel('excess corr')
axis tight
hold off;
%% polar distr phase clustering, swrLickPhase, meanMRVmag
sf3 = subaxis(2,2,3);
% a = polarhistogram(swrLickPhase, 16, 'Normalization', 'pdf', 'edgealpha', 0,...
% 'facealpha', .5);
polarplot([zeros(size(out.swrLickPhase,1),1) out.swrLickPhase]', ...
repmat([0 1],size(out.swrLickPhase,1),1)', 'color', [0 0 0 .4], 'linewidth', 4);
hold on
polarplot([0; out.vecang], [0; out.meanMRVmag], 'color', [1 0 .3], 'linewidth', 4)
grid off
rticks([])
thetaticks([])
title('swr ILI-phase')
hold off
axis tight
%% phase mod
sf4 = subaxis(2,2,4);
histogram(cell2mat(out.phasemodShuf), 100, 'Normalization', 'probability', 'edgealpha', 0, 'facecolor', 'k');
hold on;
mrvsort = sort(cell2mat(out.phasemodShuf));
idxsig = round(sigpct*length(out.phasemodShuf));
line([mrvsort(idxsig) mrvsort(idxsig)], ylim, 'color', [0 0 0 .8], 'linestyle', '--');
hold on
line([out.phasemod out.phasemod], ylim, 'color', 'r');
modp = 1-sum(out.phasemod>cell2mat(out.phasemodShuf))/length(out.phasemodShuf);
title(sprintf('logMRVmag %.03f p%.03f Rpval%.03f', out.phasemod, modp, pval));
ylabel('probability')
xlabel('log(Rayleigh Z)')
axis tight
hold off

%% ---- super axis -----
sprtit = sprintf('%s %d %d %s', animal, day, epoch, fname(5:end));
setSuperAxTitle(sprtit)
% ---- pause, save figs ----
if pausefigs; pause; end
if savefigs; save_figure(outdir, sprtit, 'savefigas', savefigas); end
end
end

function out = make_blank()
out.index = [];
out.time = [];
Expand All @@ -394,7 +311,8 @@
out.swrPctSinceLick = [];
out.vecang = [];
out.phasemod = [];
%% shuffle

%% shuffle
out.swrStartShuf = [];
% xcTime
out.xcShuf = {};
Expand Down
21 changes: 7 additions & 14 deletions DFFunctions/load_filter_params.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,34 +159,27 @@
% Fp.minstdthresh,'maxvelocity',Fp.maxvelocity,'minvelocity', ...
% Fp.minvelocity, 'consensus_numtets',Fp.consensus_numtets,'welldist', ...
% Fp.welldist);

%% filter function specific params

case 'dfa_reactivationPSTH'
bin = 0.025; % seconds
win = [-2 2];
perPC = 1;

consensus_numtets = 2; % minimum # of tets for consensus event detection
minstdthresh = 3; % STD. how big your ripples are
exclusion_dur = 0; % seconds within which consecutive events are eliminated / ignored
minvelocity = 0;
maxvelocity = 4;
maxIntraBurstILI = 0.25; % max burst ili threshold in seconds
minBoutLicks = 3; % filter out bouts with less than boutNum licks
minTimeFromLick = .5; % time duration from closest lick
minLickTimeFromSwr = 1; % time duration from closest lick

iterator = 'singleepochanal';
datatypes = {'spikes', 'lick', 'ca1rippleskons', 'cellinfo'};
options = {'cellfilter', cellfilter, 'win', win, 'bin', bin, ...
'swrTimeFilter', ...
[{{'getconstimes', '($cons == 1)', ...
'ca1rippleskons', 1,'consensus_numtets',consensus_numtets, ...
'minstdthresh', minstdthresh,'exclusion_dur',exclusion_dur, ...
'minvelocity', minvelocity,'maxvelocity',maxvelocity}}, ...
{{'getpriortofirstwell', '($prefirst == 0)'}}], ...
options = {'cellfilter', cellfilter, 'win', win, 'bin', bin, 'perPC', perPC,...
'templateFilter', ...
{{'get2dstate','($velocity>4)'}}, ...
'burstTimeFilter', ...
{{'getLickBout', '($lickBout == 1)', 'maxIntraBurstILI', maxIntraBurstILI, ...
'minBoutLicks', minBoutLicks}}};


case 'swrlickmod'
filtfunction = 'swrlickmod';

Expand Down
7 changes: 6 additions & 1 deletion DFFunctions/load_plotting_params.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
SupFontS = 12;
tickSz = 8; % tick labels font size
set(0,'defaultAxesFontSize',10)

case 'Reactivation PerPC'
position = [.1 .1 .5 .5];
winSE = [-2 2];

case 'areaTFspect'
% area = {{'mec', 'sup'}, {'mec', 'deep'}, {'ca1', 'd'}};
position = [.1 .1 .8 .5];
win = [-.5 .5];
usecolormap = hot;
tickFsize = 8;
case 'ReactivationStrength'
case 'Reactivation Full'
position = [.1 .1 .5 .5];
winSE = [-2 2];
case 'wetVDryILIphaseSWR'
Expand Down
63 changes: 63 additions & 0 deletions Functions/vals2rgb.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
function rgb = vals2rgb(vals, colormap, crange)
% Take in a vector of N values and return and return a Nx3 matrix of RGB
% values associated with a given colormap
%
% rgb = AFQ_vals2colormap(vals, [colormap = 'jet'], [crange])
%
% Inputs:
% vals = A vector of values to map to a colormap or a cell array of
% vectors of values
% colormap = A matlab colormap. Examples: colormap = 'autumn';
% colormap = 'jet'; colormap = 'hot';
% crange = The values to map to the minimum and maximum of the colormap.
% Defualts to the full range of values in vals.
%
% Outputs:
% rgb = Nx3 matrix of rgb values mapping each value in vals to the
% corresponding rgb colors. If vals is a cell array then rgb
% will be a cell array of the same length
%
% Example:
% vals = rand(1,100);
% rgb = AFQ_vals2colormap(vals, 'hot');
%
% Copyright Jason D. Yeatman, June 2012

if ~exist('colormap','var') || isempty(colormap)
colormap = 'jet';
end

%
if ~iscell(vals)
if ~exist('crange','var') || isempty(crange)
crange = [min(vals) max(vals)];
end
% Generate the colormap
cmap = eval([colormap '(256)']);
% Normalize the values to be between 1 and 256
vals(vals < crange(1)) = crange(1);
vals(vals > crange(2)) = crange(2);
valsN = round(((vals - crange(1)) ./ diff(crange)) .* 255)+1;
% Convert any nans to ones
valsN(isnan(valsN)) = 1;
% Convert the normalized values to the RGB values of the colormap
rgb = cmap(valsN, :);
elseif iscell(vals)
if ~exist('crange','var') || isempty(crange)
crange = [min(vertcat(vals{:})) max(vertcat(vals{:}))];
end
% Generate the colormap
cmap = eval([colormap '(256)']);
for ii = 1:length(vals)
% Normalize the values to be between 1 and 256 for cell ii
valsN = vals{ii};
valsN(valsN < crange(1)) = crange(1);
valsN(valsN > crange(2)) = crange(2);
valsN = round(((valsN - crange(1)) ./ diff(crange)) .* 255)+1;
% Convert any nans to ones
valsN(isnan(valsN)) = 1;
% Convert the normalized values to the RGB values of the colormap
rgb{ii} = cmap(valsN, :);
end
end
return
Binary file added clusterless_decode/Bon__4_6_fullep.mat
Binary file not shown.
Loading

0 comments on commit 7a05997

Please sign in to comment.