Skip to content

Commit

Permalink
removed old matlab code from repo
Browse files Browse the repository at this point in the history
  • Loading branch information
droumis committed May 6, 2020
1 parent 0cef1c2 commit 2895a8e
Show file tree
Hide file tree
Showing 23,515 changed files with 122 additions and 10,343,034 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,17 @@


% if (appendindex)
% out.index = ind;
% out.index = ind;
% end
out.index = ind;
out.T = T;
out.T = T;
out.p1p2 = exp_p;
out.corr = xc;
out.rawcorr = rawcorr;
out.Zcrosscov = Zcrosscov;
out.Zcrosscov = Zcrosscov; %% i think used to calc stats? but also plotted
out.crosscov = crosscov;
out.rawcorr_sm = rawcorr_sm;
out.Zcrosscov_sm = Zcrosscov_sm;
out.Zcrosscov_sm = Zcrosscov_sm; %% USED to plot
out.crosscov_sm = crosscov_sm;
out.Neventscorr = Neventscorr;

Expand Down
100 changes: 68 additions & 32 deletions DFAnalysis/dfa_phaseXcorr.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
% 'bin', n binsize in sec. Default 0.002 (2 ms)
% 'tmax', n maximum time for cross correlation. Default 1 sec.

bin = .001; % s
tmax = .5; % s
bin = 0.01; % seconds
sw1 = bin*3; % seconds
sw2 = 0.250;
rmstmax = 0.1;
rmsmincounts = 50;
tmax = 1;
try assign(varargin{:}); catch; end

% check for required data in varargin
Expand All @@ -21,7 +25,6 @@
end
end

% fuck this won't work for pairs..
day = idx(1);
ntA = idx(2);
clustA = idx(3);
Expand All @@ -30,6 +33,8 @@
eps = idx(6:end);

out = init_out();
out.index = idx;

% for each cell we calculate the cross correlation
t1 = [];
t2 = [];
Expand All @@ -54,39 +59,69 @@
%% get lickbout licks
[intraBoutXP, ~] = getLickBoutLicks(animal, [repmat(day,length(eps),1) eps'], varargin);
intraBoutXPvec = intraBoutXP{day}{eps};
eventTimes = intraBoutXPvec(ismember(intraBoutXPvec, eventTimes));
licks = cell2mat([arrayfun(@(x) lick{day}{x}.starttime, eps, 'un', 0)']);
eventTimes = intraBoutXPvec(ismember(intraBoutXPvec, licks));

numEventsPerEp = [];
for e = 1:length(eps)
epStartTime = spikes{day}{eps(e)}{nt}{clust}.timerange(1);
epEndTime = spikes{day}{eps(e)}{nt}{clust}.timerange(2);
numEventsPerEp = [numEventsPerEp; sum(logical(isExcluded(eventTimes, [epStartTime epEndTime])))];
end
% numEventsPerEp = [];
% for e = 1:length(eps)
% epStartTime = spikes{day}{eps(e)}{nt}{clust}.timerange(1);
% epEndTime = spikes{day}{eps(e)}{nt}{clust}.timerange(2);
% numEventsPerEp = [numEventsPerEp; sum(logical(isExcluded(eventTimes, [epStartTime epEndTime])))];
% end

%% transform spikes into a phase vector
% how? each spike is a spike time.. i need each spike time relative to
% preceeding lick then ratio to interlickinterval duration to get %.. then
% radians.. then that + (2pi*[preceding lick number])

% spiketrain A
% ILI = diff(eventTimes); % diff gives duration from each lick to the next
[~, ~, spikebin] = histcounts(t1cnd, eventTimes);
spikesILImask = spikebin~=0;
t1LB = t1cnd(spikesILImask);
binTimeStart = eventTimes(spikebin(spikesILImask));
binTimeEnd = eventTimes(spikebin(spikesILImask)+1);

ILI = (binTimeEnd - binTimeStart);
t1FromLick = (t1LB - binTimeStart);

pctSpikeILI = t1FromLick./ILI;

% for each valid ILI, increment its spikes to be pct of ILI + the ILI index
t1SpikePctILIbin = spikebin(spikesILImask)+pctSpikeILI;

% spiketrain B
[~, ~, spikebin] = histcounts(t2cnd, eventTimes);
spikesILImask = spikebin~=0;
t2LB = t2cnd(spikesILImask);
binTimeStart = eventTimes(spikebin(spikesILImask));
binTimeEnd = eventTimes(spikebin(spikesILImask)+1);

ILI = (binTimeEnd - binTimeStart);
t2FromLick = (t2LB - binTimeStart);

pctSpikeILI = t2FromLick./ILI;

% for each valid ILI, increment its spikes to be pct of ILI + the ILI index
t2SpikePctILIbin = spikebin(spikesILImask)+pctSpikeILI;

%% run phase xcorr

% get xc
xc = spikexcorr(t1cnd,t2cnd, bin, tmax);
xc = spikexcorr(t1SpikePctILIbin,t2SpikePctILIbin, bin, tmax);
% normalize
normxc = xc.c1vsc2 ./ sqrt(xc.nspikes1 * xc.nspikes2);
% smooth
try
nstd=round(sw1/(xc.time(2) - xc.time(1)));
catch
if xc.nspikes1 == 0
emptynt = index(3:4);
elseif xc.nspikes2 == 0
emptynt = index(5:6);
end
fprintf('no spikes %d %d %d %d\n', day, epoch, emptynt(1),emptynt(2))
out = make_blank(index);
% if xc.nspikes1 == 0
% emptynt = index(3:4);
% elseif xc.nspikes2 == 0
% emptynt = index(5:6);
% end
fprintf('missing spikes \n') %d %d %d %d %d %d\n', day, epoch, emptynt(1),emptynt(2))
% out = make_blank(index);
return
end
g1 = gaussian(nstd, 2*nstd+1);
Expand All @@ -95,35 +130,36 @@
% bins = find(abs(xc.time)<=0.2);
% Neventscorr = sum(xc.c1vsc2(bins));
% Expected probability
p1 = xc.nspikes1/T;
p2 = xc.nspikes2/T; % fr in Hz
expProb = p1*p2; % per sec

% p1 = xc.nspikes1/T;
% p2 = xc.nspikes2/T; % fr in Hz
% expProb = p1*p2; % per sec

% compute the excess correlation at 0 lag
exc = excesscorr(xc.time, xc.c1vsc2, xc.nspikes1, xc.nspikes2, sw1, sw2);
% compute RMS
xcrms = xcorrrms(xc.time, xc.c1vsc2, rmstmax, rmsmincounts);

% output
out.index = index;
out.bin = bin;
out.tmax = tmax;
% out.T = T;
out.xc = xc;
out.normxc = normxc;
out.smthxc = smthxc;
out.expProb = expProb;
% out.expProb = expProb;
% out.xcShfmean = xcShfmean;
% out.xcShfLag0 = xcShfLag0;
out.excesscorr = nanmean(exc); % nanmean in case there are two bins equally near lag zero
out.xcrms = xcrms;
end

function out = init_out()
out.tmax = [];
out.bin = [];
out.xc = [];
out.normxc = [];
out.smthxc = [];
out.expProb = [];
out.excesscorr = [];
out.xcrms = [];
out.tmax = nan;
out.bin = nan;
out.xc = nan;
out.normxc = nan;
out.smthxc = nan;
% out.expProb = [];
out.excesscorr = nan;
out.xcrms = nan;
end
2 changes: 1 addition & 1 deletion DFFunctions/Iterators/iter_multiEpoch_multiCluster.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
clustB = unqNtCell(c,4);
eps = f(a).epochs{g}(deIdx,2)';
cindex = [day ntA clustA ntB clustB eps];
fprintf('--%s %s day %d nt %d cl %d :: eps %s\n', f(a).function.name, ...
fprintf('--%s %s day %d nt-cl %d-%d x %d-%d :: eps %s\n', f(a).function.name, ...
f(a).animal{1}, day, ntA, clustA, ntB, clustB,...
strjoin(num2cell(num2str(eps(:)))',' '));
% run the specified filter function on this day cell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
all_trialResps1_epcomb=[]; all_trialResps2_epcomb=[]; all_trialResps1rdm_epcomb=[]; all_trialResps2rdm_epcomb=[];
r=[]; p=[]; r_rdm=[]; p_rdm=[];

for r=ind
for r=inde
% Theta Corr variables
% --------------------
allZcrosscov_sm_runtheta_epcomb = [allZcrosscov_sm_runtheta_epcomb; allZcrosscov_sm_runtheta(r,:)];
Expand Down Expand Up @@ -627,7 +627,7 @@
line([0.1 0.1], [min(runthetaZ) max(runthetaZ)],'Color',[0.5 0.5 0.5],'LineWidth',1);
line([-0.1 -0.1], [min(runthetaZ) max(runthetaZ)],'Color',[0.5 0.5 0.5],'LineWidth',1);

title(sprintf('Mean Std. CrossCov - Rip %s Cells',...
title(sprintf('Mean Cov - Rip %s Cells',...
kind),'FontSize',20)
set(gca,'XLim',[-0.4 0.4]);
xlabel('Time (sec)','FontSize',20);
Expand Down
Loading

0 comments on commit 2895a8e

Please sign in to comment.