Skip to content

Commit

Permalink
updates to loadSpikes and channemap
Browse files Browse the repository at this point in the history
  • Loading branch information
petersenpeter committed Jan 16, 2020
1 parent 1e25ad4 commit 43b8bdd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
10 changes: 5 additions & 5 deletions createChannelMapFile_KSW.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ function createChannelMapFile_Local(basepath,basename,electrode_type)
% % order = [par.AnatGrps.Channels];
% % skip = find([par.AnatGrps.Skip]);
% % connected(order(skip)+1) = false;
% order = [par.AnatGrps.Channels];
% if isfield(par,'SpkGrps')
% skip2 = find(~ismember([par.AnatGrps.Channels], [par.SpkGrps.Channels])); % finds the indices of the channels that are not part of SpkGrps
% connected(order(skip2)+1) = false;
% end
order = [par.AnatGrps.Channels];
if isfield(par,'SpkGrps')
skip2 = find(~ismember([par.AnatGrps.Channels], [par.SpkGrps.Channels])); % finds the indices of the channels that are not part of SpkGrps
connected(order(skip2)+1) = false;
end

chanMap = 1:Nchannels;
chanMap0ind = chanMap - 1;
Expand Down
52 changes: 38 additions & 14 deletions loadSpikes.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
% DEPENDENCIES:
%
% LoadXml.m & xmltools.m (default) or bz_getSessionInfo.m
%
% EXAMPLE CALL
% spikes = loadSpikes('clusteringpath',KilosortOutputPath,'basepath',pwd); % Run from basepath, assumes Phy format. Requires xml file and dat file in basepath

% By Peter Petersen
% [email protected]
Expand Down Expand Up @@ -77,7 +80,7 @@
basename = session.general.name;
basepath = session.general.basePath;
clusteringFormat = session.spikeSorting{1}.format;
clusteringpath = session.general.clusteringPath;
clusteringpath = session.spikeSorting{1}.relativePath;
if isfield(session.extracellular,'leastSignificantBit') && session.extracellular.leastSignificantBit>0
LSB = session.extracellular.leastSignificantBit;
end
Expand Down Expand Up @@ -114,12 +117,11 @@
else
if ~exist('LoadXml.m','file') || ~exist('xmltools.m','file')
error('''LoadXml.m'' and ''xmltools.m'' is not in your path and is required to load the xml file. If you have buzcode installed, please set ''buzcode'' to true in the input parameters.')
else
elseif exist(fullfile(clusteringpath_full,[basename, '.xml']),'file')
xml = LoadXml(fullfile(clusteringpath_full,[basename, '.xml']));
end
end
switch lower(clusteringFormat)

% Loading klustakwik
case {'klustakwik', 'neurosuite'}
disp('loadSpikes: Loading Klustakwik data')
Expand Down Expand Up @@ -209,7 +211,7 @@
elseif exist(filename2) == 2
filename = filename2;
else
disp('Phy: No cluster group file found')
error('Phy: No cluster group file found')
end
delimiter = '\t';
startRow = 2;
Expand Down Expand Up @@ -260,7 +262,7 @@
end

% Loading klustaViewa - Kwik format (Klustasuite 0.3.0.beta4)
case 'klustaViewa'
case 'klustaviewa'
disp('loadSpikes: Loading KlustaViewa data')
shank_nb = 1;
for shank = 1:shanks
Expand All @@ -277,23 +279,40 @@
spikes.ts{shank_nb} = spike_times(cluster_index == clusters(i))+recording_nb(cluster_index == clusters(i))*40*40000;
spikes.times{shank_nb} = spikes.ts{j}/xml.SampleRate;
spikes.total(shank_nb) = sum(cluster_index == clusters(i));
spikes.shankID(shank_nb) = shank-1;
spikes.shankID(shank_nb) = shank;
spikes.cluID(shank_nb) = clusters(i);
spikes.filtWaveform_all{shank_nb} = mean(waveforms(:,:,cluster_index == clusters(i)),3);
spikes.filtWaveform_all_std{shank_nb} = permute(std(permute(waveforms(:,:,cluster_index == clusters(i)),[3,1,2])),[2,3,1]);
shank_nb = shank_nb+1;
end
end
end
if getWaveforms % get waveforms
spikes = GetWaveformsFromDat(spikes,xml,basepath,basename,LSB,session);
end

% Loading sebastienroyer's data format
case {'sebastienroyer'}
temp = load(fullfile(clusteringpath_full,[basename,'.mat']));
cluster_index = temp.spk.g;
cluster_timestamps = temp.spk.t;
clusters = unique(cluster_index);
for i = 1:length(clusters)
spikes.ts{i} = cluster_timestamps(find(cluster_index == clusters(i)));
spikes.times{i} = spikes.ts{i}/xml.SampleRate;
spikes.total(i) = length(spikes.times{i});
spikes.cluID(i) = clusters(i);
spikes.UID(i) = i;
spikes.filtWaveform_all{i} = temp.spkinfo.waveform(:,:,i);
end
if getWaveforms % get waveforms
spikes = GetWaveformsFromDat(spikes,xml,basepath,basename,LSB,session);
end
end
%
spikes.sessionName = basename;

% Generate spindices matrics
spikes.numcells = length(spikes.UID);
% Generate spindices matrics
for cc = 1:spikes.numcells
groups{cc}=spikes.UID(cc).*ones(size(spikes.times{cc}));
end
Expand Down Expand Up @@ -346,10 +365,10 @@
badChannels = [];

% Removing channels marked as Bad in session struct
if ~isempty(session)
if ~isempty(session) && isfield(session.channelTags,'Bad')
badChannels = session.channelTags.Bad.channels;
if ~isempty(session.channelTags.Bad.spikeGroups)
badChannels = [badChannels,session.extracellular.spikeGroups(session.channelTags.Bad.spikeGroups)+1];
badChannels = [badChannels,session.extracellular.electrodeGroups(session.channelTags.Bad.spikeGroups)];
end
badChannels = unique(badChannels);
end
Expand Down Expand Up @@ -389,8 +408,12 @@
clear m
error('Waveform extraction canceled by user')
end
t1 = toc(timerVal);
spkTmp = spikes.ts{ii}(find(spikes.times{ii} > wfWin_sec/1.8 & spikes.times{ii} < duration-wfWin_sec/1.8));
t1 = toc(timerVal); ;
if isfield(spikes,'ts')
spkTmp = spikes.ts{ii}(find(spikes.times{ii} > wfWin_sec/1.8 & spikes.times{ii} < duration-wfWin_sec/1.8));
else
spkTmp = round(xml.SampleRate * spikes.times{ii}(find(spikes.times{ii} > wfWin_sec/1.8 & spikes.times{ii} < duration-wfWin_sec/1.8)));
end

if length(spkTmp) > nPull
spkTmp = spkTmp(randperm(length(spkTmp)));
Expand Down Expand Up @@ -436,12 +459,13 @@
filtWaveform = mean(wfF,2)';
filtWaveform_std = std(wfF');

window_interval = wfWin-(wfWinKeep*xml.SampleRate):wfWin-1+(wfWinKeep*xml.SampleRate);
window_interval = wfWin-ceil(wfWinKeep*xml.SampleRate):wfWin-1+ceil(wfWinKeep*xml.SampleRate);
spikes.rawWaveform{ii} = rawWaveform(window_interval); % keep only +- 0.8 ms of waveform
spikes.rawWaveform_std{ii} = rawWaveform_std(window_interval);
spikes.filtWaveform{ii} = filtWaveform(window_interval);
spikes.filtWaveform_std{ii} = filtWaveform_std(window_interval);
spikes.timeWaveform{ii} = (-wfWinKeep+1/xml.SampleRate:1/xml.SampleRate:wfWinKeep)*1000;
spikes.timeWaveform{ii} = ([-ceil(wfWinKeep*xml.SampleRate)*(1/xml.SampleRate):1/xml.SampleRate:(ceil(wfWinKeep*xml.SampleRate)-1)*(1/xml.SampleRate)])*1000;
% spikes.timeWaveform{ii} = (-wfWinKeep+1/xml.SampleRate:1/xml.SampleRate:wfWinKeep)*1000;
spikes.peakVoltage(ii) = max(spikes.filtWaveform{ii})-min(spikes.filtWaveform{ii});

if ishandle(fig1)
Expand Down

0 comments on commit 43b8bdd

Please sign in to comment.