|
28 | 28 | % DEPENDENCIES:
|
29 | 29 | %
|
30 | 30 | % 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 |
31 | 34 |
|
32 | 35 | % By Peter Petersen
|
33 | 36 |
|
|
77 | 80 | basename = session.general.name;
|
78 | 81 | basepath = session.general.basePath;
|
79 | 82 | clusteringFormat = session.spikeSorting{1}.format;
|
80 |
| - clusteringpath = session.general.clusteringPath; |
| 83 | + clusteringpath = session.spikeSorting{1}.relativePath; |
81 | 84 | if isfield(session.extracellular,'leastSignificantBit') && session.extracellular.leastSignificantBit>0
|
82 | 85 | LSB = session.extracellular.leastSignificantBit;
|
83 | 86 | end
|
|
114 | 117 | else
|
115 | 118 | if ~exist('LoadXml.m','file') || ~exist('xmltools.m','file')
|
116 | 119 | 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') |
118 | 121 | xml = LoadXml(fullfile(clusteringpath_full,[basename, '.xml']));
|
119 | 122 | end
|
120 | 123 | end
|
121 | 124 | switch lower(clusteringFormat)
|
122 |
| - |
123 | 125 | % Loading klustakwik
|
124 | 126 | case {'klustakwik', 'neurosuite'}
|
125 | 127 | disp('loadSpikes: Loading Klustakwik data')
|
|
209 | 211 | elseif exist(filename2) == 2
|
210 | 212 | filename = filename2;
|
211 | 213 | else
|
212 |
| - disp('Phy: No cluster group file found') |
| 214 | + error('Phy: No cluster group file found') |
213 | 215 | end
|
214 | 216 | delimiter = '\t';
|
215 | 217 | startRow = 2;
|
|
260 | 262 | end
|
261 | 263 |
|
262 | 264 | % Loading klustaViewa - Kwik format (Klustasuite 0.3.0.beta4)
|
263 |
| - case 'klustaViewa' |
| 265 | + case 'klustaviewa' |
264 | 266 | disp('loadSpikes: Loading KlustaViewa data')
|
265 | 267 | shank_nb = 1;
|
266 | 268 | for shank = 1:shanks
|
|
277 | 279 | spikes.ts{shank_nb} = spike_times(cluster_index == clusters(i))+recording_nb(cluster_index == clusters(i))*40*40000;
|
278 | 280 | spikes.times{shank_nb} = spikes.ts{j}/xml.SampleRate;
|
279 | 281 | spikes.total(shank_nb) = sum(cluster_index == clusters(i));
|
280 |
| - spikes.shankID(shank_nb) = shank-1; |
| 282 | + spikes.shankID(shank_nb) = shank; |
281 | 283 | spikes.cluID(shank_nb) = clusters(i);
|
282 | 284 | spikes.filtWaveform_all{shank_nb} = mean(waveforms(:,:,cluster_index == clusters(i)),3);
|
283 | 285 | spikes.filtWaveform_all_std{shank_nb} = permute(std(permute(waveforms(:,:,cluster_index == clusters(i)),[3,1,2])),[2,3,1]);
|
284 | 286 | shank_nb = shank_nb+1;
|
285 | 287 | end
|
286 | 288 | end
|
287 | 289 | end
|
| 290 | + if getWaveforms % get waveforms |
| 291 | + spikes = GetWaveformsFromDat(spikes,xml,basepath,basename,LSB,session); |
| 292 | + end |
288 | 293 |
|
| 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 |
289 | 308 | if getWaveforms % get waveforms
|
290 | 309 | spikes = GetWaveformsFromDat(spikes,xml,basepath,basename,LSB,session);
|
291 | 310 | end
|
292 | 311 | end
|
| 312 | + % |
293 | 313 | spikes.sessionName = basename;
|
294 |
| - |
295 |
| - % Generate spindices matrics |
296 | 314 | spikes.numcells = length(spikes.UID);
|
| 315 | + % Generate spindices matrics |
297 | 316 | for cc = 1:spikes.numcells
|
298 | 317 | groups{cc}=spikes.UID(cc).*ones(size(spikes.times{cc}));
|
299 | 318 | end
|
|
346 | 365 | badChannels = [];
|
347 | 366 |
|
348 | 367 | % Removing channels marked as Bad in session struct
|
349 |
| -if ~isempty(session) |
| 368 | +if ~isempty(session) && isfield(session.channelTags,'Bad') |
350 | 369 | badChannels = session.channelTags.Bad.channels;
|
351 | 370 | 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)]; |
353 | 372 | end
|
354 | 373 | badChannels = unique(badChannels);
|
355 | 374 | end
|
|
389 | 408 | clear m
|
390 | 409 | error('Waveform extraction canceled by user')
|
391 | 410 | 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 |
394 | 417 |
|
395 | 418 | if length(spkTmp) > nPull
|
396 | 419 | spkTmp = spkTmp(randperm(length(spkTmp)));
|
|
436 | 459 | filtWaveform = mean(wfF,2)';
|
437 | 460 | filtWaveform_std = std(wfF');
|
438 | 461 |
|
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); |
440 | 463 | spikes.rawWaveform{ii} = rawWaveform(window_interval); % keep only +- 0.8 ms of waveform
|
441 | 464 | spikes.rawWaveform_std{ii} = rawWaveform_std(window_interval);
|
442 | 465 | spikes.filtWaveform{ii} = filtWaveform(window_interval);
|
443 | 466 | 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; |
445 | 469 | spikes.peakVoltage(ii) = max(spikes.filtWaveform{ii})-min(spikes.filtWaveform{ii});
|
446 | 470 |
|
447 | 471 | if ishandle(fig1)
|
|
0 commit comments