Skip to content

Commit 43b8bdd

Browse files
committed
updates to loadSpikes and channemap
1 parent 1e25ad4 commit 43b8bdd

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

createChannelMapFile_KSW.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ function createChannelMapFile_Local(basepath,basename,electrode_type)
153153
% % order = [par.AnatGrps.Channels];
154154
% % skip = find([par.AnatGrps.Skip]);
155155
% % connected(order(skip)+1) = false;
156-
% order = [par.AnatGrps.Channels];
157-
% if isfield(par,'SpkGrps')
158-
% skip2 = find(~ismember([par.AnatGrps.Channels], [par.SpkGrps.Channels])); % finds the indices of the channels that are not part of SpkGrps
159-
% connected(order(skip2)+1) = false;
160-
% end
156+
order = [par.AnatGrps.Channels];
157+
if isfield(par,'SpkGrps')
158+
skip2 = find(~ismember([par.AnatGrps.Channels], [par.SpkGrps.Channels])); % finds the indices of the channels that are not part of SpkGrps
159+
connected(order(skip2)+1) = false;
160+
end
161161

162162
chanMap = 1:Nchannels;
163163
chanMap0ind = chanMap - 1;

loadSpikes.m

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
% DEPENDENCIES:
2929
%
3030
% LoadXml.m & xmltools.m (default) or bz_getSessionInfo.m
31+
%
32+
% EXAMPLE CALL
33+
% spikes = loadSpikes('clusteringpath',KilosortOutputPath,'basepath',pwd); % Run from basepath, assumes Phy format. Requires xml file and dat file in basepath
3134

3235
% By Peter Petersen
3336
@@ -77,7 +80,7 @@
7780
basename = session.general.name;
7881
basepath = session.general.basePath;
7982
clusteringFormat = session.spikeSorting{1}.format;
80-
clusteringpath = session.general.clusteringPath;
83+
clusteringpath = session.spikeSorting{1}.relativePath;
8184
if isfield(session.extracellular,'leastSignificantBit') && session.extracellular.leastSignificantBit>0
8285
LSB = session.extracellular.leastSignificantBit;
8386
end
@@ -114,12 +117,11 @@
114117
else
115118
if ~exist('LoadXml.m','file') || ~exist('xmltools.m','file')
116119
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.')
117-
else
120+
elseif exist(fullfile(clusteringpath_full,[basename, '.xml']),'file')
118121
xml = LoadXml(fullfile(clusteringpath_full,[basename, '.xml']));
119122
end
120123
end
121124
switch lower(clusteringFormat)
122-
123125
% Loading klustakwik
124126
case {'klustakwik', 'neurosuite'}
125127
disp('loadSpikes: Loading Klustakwik data')
@@ -209,7 +211,7 @@
209211
elseif exist(filename2) == 2
210212
filename = filename2;
211213
else
212-
disp('Phy: No cluster group file found')
214+
error('Phy: No cluster group file found')
213215
end
214216
delimiter = '\t';
215217
startRow = 2;
@@ -260,7 +262,7 @@
260262
end
261263

262264
% Loading klustaViewa - Kwik format (Klustasuite 0.3.0.beta4)
263-
case 'klustaViewa'
265+
case 'klustaviewa'
264266
disp('loadSpikes: Loading KlustaViewa data')
265267
shank_nb = 1;
266268
for shank = 1:shanks
@@ -277,23 +279,40 @@
277279
spikes.ts{shank_nb} = spike_times(cluster_index == clusters(i))+recording_nb(cluster_index == clusters(i))*40*40000;
278280
spikes.times{shank_nb} = spikes.ts{j}/xml.SampleRate;
279281
spikes.total(shank_nb) = sum(cluster_index == clusters(i));
280-
spikes.shankID(shank_nb) = shank-1;
282+
spikes.shankID(shank_nb) = shank;
281283
spikes.cluID(shank_nb) = clusters(i);
282284
spikes.filtWaveform_all{shank_nb} = mean(waveforms(:,:,cluster_index == clusters(i)),3);
283285
spikes.filtWaveform_all_std{shank_nb} = permute(std(permute(waveforms(:,:,cluster_index == clusters(i)),[3,1,2])),[2,3,1]);
284286
shank_nb = shank_nb+1;
285287
end
286288
end
287289
end
290+
if getWaveforms % get waveforms
291+
spikes = GetWaveformsFromDat(spikes,xml,basepath,basename,LSB,session);
292+
end
288293

294+
% Loading sebastienroyer's data format
295+
case {'sebastienroyer'}
296+
temp = load(fullfile(clusteringpath_full,[basename,'.mat']));
297+
cluster_index = temp.spk.g;
298+
cluster_timestamps = temp.spk.t;
299+
clusters = unique(cluster_index);
300+
for i = 1:length(clusters)
301+
spikes.ts{i} = cluster_timestamps(find(cluster_index == clusters(i)));
302+
spikes.times{i} = spikes.ts{i}/xml.SampleRate;
303+
spikes.total(i) = length(spikes.times{i});
304+
spikes.cluID(i) = clusters(i);
305+
spikes.UID(i) = i;
306+
spikes.filtWaveform_all{i} = temp.spkinfo.waveform(:,:,i);
307+
end
289308
if getWaveforms % get waveforms
290309
spikes = GetWaveformsFromDat(spikes,xml,basepath,basename,LSB,session);
291310
end
292311
end
312+
%
293313
spikes.sessionName = basename;
294-
295-
% Generate spindices matrics
296314
spikes.numcells = length(spikes.UID);
315+
% Generate spindices matrics
297316
for cc = 1:spikes.numcells
298317
groups{cc}=spikes.UID(cc).*ones(size(spikes.times{cc}));
299318
end
@@ -346,10 +365,10 @@
346365
badChannels = [];
347366

348367
% Removing channels marked as Bad in session struct
349-
if ~isempty(session)
368+
if ~isempty(session) && isfield(session.channelTags,'Bad')
350369
badChannels = session.channelTags.Bad.channels;
351370
if ~isempty(session.channelTags.Bad.spikeGroups)
352-
badChannels = [badChannels,session.extracellular.spikeGroups(session.channelTags.Bad.spikeGroups)+1];
371+
badChannels = [badChannels,session.extracellular.electrodeGroups(session.channelTags.Bad.spikeGroups)];
353372
end
354373
badChannels = unique(badChannels);
355374
end
@@ -389,8 +408,12 @@
389408
clear m
390409
error('Waveform extraction canceled by user')
391410
end
392-
t1 = toc(timerVal);
393-
spkTmp = spikes.ts{ii}(find(spikes.times{ii} > wfWin_sec/1.8 & spikes.times{ii} < duration-wfWin_sec/1.8));
411+
t1 = toc(timerVal); ;
412+
if isfield(spikes,'ts')
413+
spkTmp = spikes.ts{ii}(find(spikes.times{ii} > wfWin_sec/1.8 & spikes.times{ii} < duration-wfWin_sec/1.8));
414+
else
415+
spkTmp = round(xml.SampleRate * spikes.times{ii}(find(spikes.times{ii} > wfWin_sec/1.8 & spikes.times{ii} < duration-wfWin_sec/1.8)));
416+
end
394417

395418
if length(spkTmp) > nPull
396419
spkTmp = spkTmp(randperm(length(spkTmp)));
@@ -436,12 +459,13 @@
436459
filtWaveform = mean(wfF,2)';
437460
filtWaveform_std = std(wfF');
438461

439-
window_interval = wfWin-(wfWinKeep*xml.SampleRate):wfWin-1+(wfWinKeep*xml.SampleRate);
462+
window_interval = wfWin-ceil(wfWinKeep*xml.SampleRate):wfWin-1+ceil(wfWinKeep*xml.SampleRate);
440463
spikes.rawWaveform{ii} = rawWaveform(window_interval); % keep only +- 0.8 ms of waveform
441464
spikes.rawWaveform_std{ii} = rawWaveform_std(window_interval);
442465
spikes.filtWaveform{ii} = filtWaveform(window_interval);
443466
spikes.filtWaveform_std{ii} = filtWaveform_std(window_interval);
444-
spikes.timeWaveform{ii} = (-wfWinKeep+1/xml.SampleRate:1/xml.SampleRate:wfWinKeep)*1000;
467+
spikes.timeWaveform{ii} = ([-ceil(wfWinKeep*xml.SampleRate)*(1/xml.SampleRate):1/xml.SampleRate:(ceil(wfWinKeep*xml.SampleRate)-1)*(1/xml.SampleRate)])*1000;
468+
% spikes.timeWaveform{ii} = (-wfWinKeep+1/xml.SampleRate:1/xml.SampleRate:wfWinKeep)*1000;
445469
spikes.peakVoltage(ii) = max(spikes.filtWaveform{ii})-min(spikes.filtWaveform{ii});
446470

447471
if ishandle(fig1)

0 commit comments

Comments
 (0)