Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bz_RankOrder #369

Closed
wants to merge 57 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f5f9045
Merge pull request #2 from buzsakilab/master
eliezyer Dec 1, 2018
3348bd5
Updating the function to be more general
eliezyer Mar 13, 2019
830a476
Update bz_PhaseModulation
eliezyer May 24, 2019
22c3a4d
Merge pull request #19 from buzsakilab/dev
brendonw1 Aug 14, 2019
8ccf8fe
Update bz_PhaseModulation.m
eliezyer Aug 22, 2019
978a8d7
Merge branch 'dev' into dev_EFO
eliezyer Oct 28, 2019
6f616ef
Merge pull request #352 from eliezyer/dev_EFO
dlevenstein Oct 28, 2019
32db167
new place field function 1
AntonioFR8 Oct 29, 2019
d0271ca
Revert "new place field function 1"
AntonioFR8 Oct 29, 2019
c5b1bb7
new place field function 1
AntonioFR8 Oct 29, 2019
eac3cfe
Merge pull request #353 from AntonioFR8/devAFR
AntonioFR8 Oct 29, 2019
8b0e855
Update bz_GetSpikes.m
valegarman Oct 29, 2019
943a0bb
Merge remote-tracking branch 'upstream/dev' into dev
valegarman Oct 29, 2019
d8a984d
Revert "Update bz_GetSpikes.m"
valegarman Oct 29, 2019
0aea1a5
new detecct swr
valegarman Oct 29, 2019
2236e93
Merge pull request #356 from valegarman/MVdev
valegarman Oct 29, 2019
ce59a96
Update bz_firingMapAvg.m
AntonioFR8 Oct 29, 2019
f50ac96
Merge pull request #357 from AntonioFR8/devAFR
AntonioFR8 Oct 29, 2019
27eb92d
Merge branch 'dev' into MVdev
valegarman Oct 29, 2019
b9f6e54
Update bz_GetSpikes.m
valegarman Oct 29, 2019
90f2a3c
Merge remote-tracking branch 'upstream/dev' into MVdev
valegarman Oct 29, 2019
00fcdf5
Update bz_firingMapAvg.m
valegarman Oct 29, 2019
c4d2861
Update bz_GetSpikes.m
valegarman Oct 29, 2019
dd5327c
temporary find place fields
AntonioFR8 Oct 29, 2019
fe22cc3
Merge pull request #358 from valegarman/MVdev
AntonioFR8 Oct 29, 2019
aeef521
Update bz_findPlaceFields1D.m
AntonioFR8 Oct 29, 2019
330eab9
Merge pull request #359 from AntonioFR8/devAFR
AntonioFR8 Oct 29, 2019
6346056
Update bz_findPlaceFields1D.m
valegarman Oct 30, 2019
096c78d
Merge pull request #361 from valegarman/MVdev
valegarman Oct 30, 2019
3b59c36
Merge pull request #3 from buzsakilab/dev
eliezyer Oct 30, 2019
81c9729
new function bz_getRipSpikes
AntonioFR8 Oct 31, 2019
e4b7030
Merge pull request #362 from AntonioFR8/devAFR
AntonioFR8 Oct 31, 2019
f5adf8e
Deleting old CFC/MI function, updating bz_CrossFreqMod to have a hilb…
eliezyer Oct 31, 2019
7555dfb
updating the help of bz_CFC_PhaseAmp
eliezyer Oct 31, 2019
840dfda
updating bz_PhaseAmplitudeDist, I've increased the freedom for the us…
eliezyer Oct 31, 2019
df1c5c3
last updates of the day on bz_PhaseAmplitudeDist
eliezyer Oct 31, 2019
f51b5f1
major folder reorganization and some new functions
AntonioFR8 Oct 31, 2019
30b829f
Merge pull request #363 from AntonioFR8/devAFR
AntonioFR8 Nov 1, 2019
0dd055a
Made intan read be subfunction of bz_DatFileMetadata.m
jhartner Nov 1, 2019
38ac586
Merge remote-tracking branch 'origin/WatsonLabWorkingBranch' into Wat…
jhartner Nov 1, 2019
d666009
Merge pull request #20 from buzsakilab/dev
jhartner Nov 1, 2019
1ebc4ff
Merge pull request #364 from brendonw1/WatsonLabWorkingBranch
dlevenstein Nov 1, 2019
3ab46c8
bz_LFPfromDat.m: Gave option to specify no GPU use
jhartner Nov 1, 2019
6ff429c
Merge remote-tracking branch 'origin/WatsonLabWorkingBranch' into Wat…
jhartner Nov 1, 2019
61ec84a
Merge pull request #365 from brendonw1/WatsonLabWorkingBranch
AntonioFR8 Nov 2, 2019
62a449e
update monosyn detection, add synapsemble code
rhuszar Nov 2, 2019
29db08c
Merge pull request #366 from buzsakilab/RHdev
rhuszar Nov 2, 2019
1506cd4
add function to extract accelerometer data
rhuszar Nov 3, 2019
6928ca2
Merge pull request #367 from buzsakilab/RHdev
rhuszar Nov 4, 2019
ad88eff
updates on CFC functions
eliezyer Nov 4, 2019
e12f645
updating my branch
eliezyer Nov 4, 2019
7b81094
Merge pull request #368 from eliezyer/dev_EFO
dlevenstein Nov 4, 2019
2506791
Tweaks to findripple param saving and comments & EventViewPlot semicolon
brendonw1 Nov 9, 2019
c5b9163
First draft of Rank Order analysis
acnavasolive Nov 14, 2019
cc269b3
Update bz_RankOrder
acnavasolive Nov 15, 2019
fcc6194
Updating bz_RankOrder: correlation against external template
acnavasolive Nov 18, 2019
edf58fe
Update bz_RankOrder documentation
acnavasolive Nov 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 224 additions & 0 deletions analysis/spikes/placeFields/bz_findPlaceFields1D.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
function [mapStats] = bz_findPlaceFields1D(firingMaps,varargin)
% [stats] = bz_findPlaceFields1D(firingMaps)
% Find place fields from 1D firing maps. Reads the output of bz_firingMapAvg

% =========================================================================
% Properties Values
% -------------------------------------------------------------------------
% 'threshold' values above threshold*peak belong to the field
% (default = 0.2)
% 'minSize' fields smaller than this size are considered spurious
% and ignored (default = 10)
% 'maxSize' fields larger than this size are considered spurious
% and ignored (default = 50)
% 'minPeak' peaks smaller than this size are considered spurious
% and ignored (default = 1)
% 'verbose' display processing information (default = 'off')
% =========================================================================

% Antonio FR, 10/2019

%%%%%%%%%%%%%% WORK IN PROGRESS

%% Parse inputs
p=inputParser;
addParameter(p,'threshold',0.2,@isnumeric);
addParameter(p,'minSize',10,@isnumeric);
addParameter(p,'minPeak',1,@isnumeric);
addParameter(p,'verbose','off',@isstr);

parse(p,varargin{:});
threshold = p.Results.threshold;
minSize = p.Results.minSize;
minPeak = p.Results.minPeak;
verbose = p.Results.verbose;


%% Find place fields
for unit = 1:length(firingMaps.rateMaps)
for c = 1:length(firingMaps.rateMaps{1})

% Default values
mapStats{unit,1}{c}.x = NaN;
mapStats{unit,1}{c}.field = [];
mapStats{unit,1}{c}.size = 0;
mapStats{unit,1}{c}.peak = 0;
mapStats{unit,1}{c}.mean = 0;
mapStats{unit,1}{c}.fieldX = [NaN NaN];
mapStats{unit,1}{c}.specificity = 0;
mapStats{unit,1}{c}.m = nan;
mapStats{unit,1}{c}.r = nan;
mapStats{unit,1}{c}.mode = nan;
mapStats{unit,1}{c}.k = nan;

% Determine the field as the connex area around the peak where the value or rate is > threshold*peak
% There can be two or more fields
z = firingMaps.rateMaps{unit}{c};
x = 1:1:length( firingMaps.rateMaps{1}{1});

if max(max(z)) == 0,
mapStats{unit,1}{c}.field = logical(zeros(size(z)));
return;
end

nBinsX = max([1 length(x)]); % minimum number of bins is 1
circX = 0; circY = 0;
% Each time we find a field, we will remove it from the map; make a copy first
% Try to find more fields until no remaining bin exceeds min value
i=1;
while true,
% Are there any candidate (unvisited) peaks left?
[peak,idx] = max(z(:));
if peak < minPeak, break; end
% Determine coordinates of largest candidate peak
[y,x] = ind2sub(size(z),idx);
% Find field (using min threshold for inclusion)
field1 = FindFieldHelper(z,x,y,peak*threshold,circX,circY);
size1 = sum(field1(:));
% Does this field include two coalescent subfields?
% To answer this question, we simply re-run the same field-searching procedure on the field
% we then either keep the original field or choose the subfield if the latter is less than
% 1/2 the size of the former
m = peak*threshold;
field2 = FindFieldHelper(z-m,x,y,(peak-m)*threshold,circX,circY);
size2 = sum(field2(:));
if size2< 1/2*size1,
field = field2;
tc = ' ';sc = '*'; % for debugging messages
else
field = field1;
tc = '*';sc = ' '; % for debugging messages
end
% Display debugging info
% if verbose,
% disp([int2zstr(i,2) ') peak ' num2str(peak) ' @ (' int2str(x) ',' int2str(y) ')']);
% disp([' ' tc ' field size ' int2str(size1)]);
% disp([' ' sc ' subfield size ' int2str(size2)]);
% disp(' ');
% figure;
% if nDims == 1,
% plot(z);hold on;
% PlotIntervals(ToIntervals(field1),'rectangles');
% PlotIntervals(ToIntervals(field2),'bars');
% ylabel(tc);
% else
% subplot(3,1,1);imagesc(z);xlabel('Data');
% subplot(3,1,2);imagesc(field1);clim([0 1]);xlabel('Field');
% subplot(3,1,3);imagesc(field2);clim([0 1]);ylabel(tc);xlabel('Subfield');
% end
% end
fieldSize = sum(field(:));
% Keep this field if its size is sufficient
if fieldSize > minSize
mapStats{unit,1}{c}.field(:,i) = field;
mapStats{unit,1}{c}.size(i) = fieldSize;
mapStats{unit,1}{c}.peak(i) = peak;
mapStats{unit,1}{c}.mean(i) = mean(z(field));
idx = find(field & z == peak);
[mapStats{unit,1}{c}.y(i),mapStats{unit,1}{c}.x(i)] = ind2sub(size(z),idx(1));
[x,y] = FieldBoundaries(field,circX,circY);
[mapStats{unit,1}{c}.fieldX(i,:),mapStats{unit,1}{c}.fieldY(i,:)] = FieldBoundaries(field,circX,circY);
i = i + 1;
end
% Mark field bins as visited
z(field) = NaN;
if all(isnan(z)), break; end
end

end
end

%% Refine place fields
%%% this is not working yet
secondaryPF = 0.6; %secondary PF should have peak FR hihger than secondayPF*peakFR of primary PF

for unit = 1:length(firingMaps.rateMaps)
for c = 1:length(firingMaps.rateMaps{1})
if mapStats{unit}{c}.peak ~= 0
for k=1:length(stats{unit}{1}.peak) % for each PF of this cell
if mapStats{unit}{c}.peak(k)>mapStats{unit}{c}.peak(1)*secondaryPF % destroy small secondary PFs
peakLoc(k)=firingMaps.rateMaps{unit}{c}.x(mapStats{unit}{c}.x(k));
scatter(peakLoc(k),mapStats{unit}{c}.peak(k),'MarkerFaceColor','r','LineWidth',1);
fieldIni(k)=firingMaps.rateMaps{unit}{c}.x(mapStats{unit}{c}.fieldX(k,1));
fieldFin(k)=firingMaps.rateMaps{unit}{c}.x(mapStats{unit}{c}.fieldX(k,2));
x1=fieldIni(k);y1=get(gca,'ylim');hold on; plot([x1 x1],y1,'-.k','LineWidth',1);
x2=fieldFin(k);y1=get(gca,'ylim');hold on; plot([x2 x2],y1,'-.k','LineWidth',1);
else
mapStats{unit}{c}.x(k) = NaN; mapStats{unit}{c}.y(k) = NaN;
mapStats{unit}{c}.field(k) = 0; mapStats{unit}{c}.size(k) = 0;
mapStats{unit}{c}.peak(k) = 0; mapStats{unit}{c}.mean(k) = 0;
mapStats{unit}{c}.fieldX(k,1:2) = [NaN,NaN]; mapStats{unit}{c}.fieldY(k,1:2) = [NaN,NaN];
end
end
for k=1:length(mapStats{unit}{c}.peak)% destroy too large PF (CHANGE for recalculate!!)
if mapStats{unit}{c}.peak(k)~=0 && ...
firingMaps.rateMaps{unit}{c}.x(stats{i}{1}.fieldX(k,2))-firingMaps.rateMaps{unit}{c}.x(mapStats{unit}{c}.fieldX(k,1)) > 0.5
mapStats{unit}{c}.x(k) = NaN; mapStats{unit}{c}.y(k) = NaN;
mapStats{unit}{c}.field(k) = 0; mapStats{unit}{c}.size(k) = 0;
mapStats{unit}{c}.peak(k) = 0; mapStats{unit}{c}.mean(k) = 0;
mapStats{unit}{c}.fieldX(k,1:2) = [NaN,NaN]; mapStats{unit}{c}.fieldY(k,1:2) = [NaN,NaN];
end
end
clear temp peakLoc fieldIni fieldFin x1 x2 y1 y2 k
end
end
end


%% Plot
for unit = 1:length(firingMaps.rateMaps)
figure;
for c = 1:length(firingMaps.rateMaps{1})
subplot(2,2,c);plot(firingMaps.rateMaps{unit}{c});
ylabel('FR(Hz)');xlabel('track (cm)');hold on;

suptitle([basename ' cell' num2str(i)]);
saveas(gcf,[pwd '\newPCs\cell_' num2str(i) '.png'],'png'); close all;


end
end

%% Write output


end


%%
% ------------------------------- Helper functions -------------------------------

% Field boundaries (circumscribed rectangle)

function [x,y] = FieldBoundaries(field,circX,circY)

% Find boundaries
x = find(any(field,1));
if isempty(x),
x = [NaN NaN];
else
x = [x(1) x(end)];
end
y = find(any(field,2));
if isempty(y),
y = [NaN NaN];
else
y = [y(1) y(end)];
end

% The above works in almost all cases; it fails however for circular coordinates if the field extends
% around an edge, e.g. for angles between 350° and 30°

if circX && x(1) == 1 && x(2) == size(field,2),
xx = find(~all(field,1));
if ~isempty(xx),
x = [xx(end) xx(1)];
end
end
if circY && y(1) == 1 && y(2) == size(field,1),
yy = find(~all(field,2));
if ~isempty(yy),
y = [yy(end) yy(1)];
end
end
end
10 changes: 10 additions & 0 deletions externalPackages/FMAToolbox/Analyses/FindFieldHelper.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function [field] = FindFieldHelper(map,x,y,threshold,circX,circY)
%[field] = FindFieldHelper(map,x,y,threshold,circX,circY)

% Helper function to pass arguments to FindField in order to avoid moving
% around compiled function

field = FindField(map,x,y,threshold,circX,circY);

end