From e074728e2997d9e3748ed0e91569d7117214d5b7 Mon Sep 17 00:00:00 2001 From: Konstantinos Date: Mon, 25 Apr 2022 19:17:48 -0400 Subject: [PATCH 1/3] Updated Kilosort events assignment Take care of no presence of any acquisition events while calling Kilosort --- toolbox/process/functions/process_spikesorting_kilosort.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/toolbox/process/functions/process_spikesorting_kilosort.m b/toolbox/process/functions/process_spikesorting_kilosort.m index 95cc80f7f..18c051db7 100644 --- a/toolbox/process/functions/process_spikesorting_kilosort.m +++ b/toolbox/process/functions/process_spikesorting_kilosort.m @@ -496,7 +496,12 @@ function ImportKilosortEvents(sFile, ChannelMat, parentPath, rez) index = index + 1; end end - events = [events events_spikes]; + + if ~isempty(existingEvents) + events = [events events_spikes]; + else + events = events_spikes; + end save(fullfile(parentPath,'events_UNSUPERVISED.mat'),'events') From a2b8f402b57755ff4ecc9d2034eb1f636bd06b6b Mon Sep 17 00:00:00 2001 From: Konstantinos Date: Tue, 26 Apr 2022 12:58:31 -0400 Subject: [PATCH 2/3] Update process_convert_raw_to_lfp.m --- toolbox/process/functions/process_convert_raw_to_lfp.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/toolbox/process/functions/process_convert_raw_to_lfp.m b/toolbox/process/functions/process_convert_raw_to_lfp.m index 5361bc2c5..5644cb8d4 100644 --- a/toolbox/process/functions/process_convert_raw_to_lfp.m +++ b/toolbox/process/functions/process_convert_raw_to_lfp.m @@ -172,7 +172,7 @@ % Template structure for the creation of the output raw file sFileTemplate = sFileIn; sFileTemplate.prop.sfreq = LFP_fs; - sFileTemplate.prop.times = [0, (nTimeOut-1) ./ LFP_fs]; + sFileTemplate.prop.times = [newTimeVector(1), newTimeVector(end)]; sFileTemplate.header.sfreq = LFP_fs; sFileTemplate.header.nsamples = nTimeOut; % Convert events to new sampling rate @@ -231,7 +231,8 @@ % Get channel name from electrode file name [tmp, ChannelName] = fileparts(ElecFile); ChannelName = strrep(ChannelName, 'raw_elec_', ''); - data = BayesianSpikeRemoval(ChannelName, data, sr, sFileIn, ChannelMat, cleanChannelNames); + data = BayesianSpikeRemoval(ChannelName, data, sr, sFileIn, ChannelMat, cleanChannelNames, BandPass); + data = data'; end % Band-pass filter data = bst_bandpass_hfilter(data, sr, BandPass(1), BandPass(2), 0, 0); @@ -242,7 +243,7 @@ %% ===== BAYESIAN SPIKE REMOVAL ===== % Reference: https://www.ncbi.nlm.nih.gov/pubmed/21068271 -function data_derived = BayesianSpikeRemoval(ChannelName, data, Fs, sFile, ChannelMat, cleanChannelNames) +function data_derived = BayesianSpikeRemoval(ChannelName, data, Fs, sFile, ChannelMat, cleanChannelNames, BandPass) % Assume that a spike lasts 3ms nSegment = round(Fs * 0.003); Bs = eye(nSegment); % 60x60 @@ -275,7 +276,7 @@ % from spktimes to obtain the start times of the spikes if mod(length(data),2)~=0 - data_temp = [data;0]; + data_temp = [data 0]'; g = fitLFPpowerSpectrum(data_temp,BandPass(1),BandPass(2),sFile.prop.sfreq); S = zeros(length(data_temp),1); iSpk = round(spkSamples - nSegment/2); From 0e42941040aa363e356137628b5f64cf2ddd0afc Mon Sep 17 00:00:00 2001 From: Konstantinos Date: Tue, 26 Apr 2022 17:57:06 -0400 Subject: [PATCH 3/3] PSTH / Raster plot Renamed PSTH per electrode to PSTH per channel. Bug fixes --- toolbox/process/functions/process_noise_correlation.m | 2 +- ...psth_per_electrode.m => process_psth_per_channel.m} | 10 +++++----- toolbox/process/functions/process_psth_per_neuron.m | 2 +- .../process/functions/process_rasterplot_per_neuron.m | 2 +- .../functions/process_spike_triggered_average.m | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) rename toolbox/process/functions/{process_psth_per_electrode.m => process_psth_per_channel.m} (94%) diff --git a/toolbox/process/functions/process_noise_correlation.m b/toolbox/process/functions/process_noise_correlation.m index 044e7e262..33f3c723a 100644 --- a/toolbox/process/functions/process_noise_correlation.m +++ b/toolbox/process/functions/process_noise_correlation.m @@ -78,7 +78,7 @@ end end % If no neuron was found - if isempty(neuronLabels) + if isempty(uniqueNeurons) bst_report('Error', sProcess, sCurrentInputs(1), 'No neurons/spiking events detected.'); return; end diff --git a/toolbox/process/functions/process_psth_per_electrode.m b/toolbox/process/functions/process_psth_per_channel.m similarity index 94% rename from toolbox/process/functions/process_psth_per_electrode.m rename to toolbox/process/functions/process_psth_per_channel.m index 434f43aeb..89258aee1 100644 --- a/toolbox/process/functions/process_psth_per_electrode.m +++ b/toolbox/process/functions/process_psth_per_channel.m @@ -1,8 +1,8 @@ -function varargout = process_psth_per_electrode( varargin ) -% PROCESS_PSTH_PER_ELECTRODE: Computes the PSTH per electrode. +function varargout = process_psth_per_channel( varargin ) +% PROCESS_PSTH_PER_ELECTRODE: Computes the PSTH per channel. -% It displays the binned firing rate on each electrode (of only the first -% neuron on each electrode if multiple have been detected). This can be nicely +% It displays the binned firing rate on each channel (of only the first +% neuron on each channel if multiple have been detected). This can be nicely % visualized on the cortical surface if the positions of the electrodes % have been set, and show real time firing rate. @@ -34,7 +34,7 @@ %% ===== GET DESCRIPTION ===== function sProcess = GetDescription() % Description the process - sProcess.Comment = 'PSTH per electrode'; + sProcess.Comment = 'PSTH per channel'; sProcess.FileTag = 'raster'; sProcess.Category = 'File'; sProcess.SubGroup = 'Electrophysiology'; diff --git a/toolbox/process/functions/process_psth_per_neuron.m b/toolbox/process/functions/process_psth_per_neuron.m index 076fec1da..a54623cc7 100644 --- a/toolbox/process/functions/process_psth_per_neuron.m +++ b/toolbox/process/functions/process_psth_per_neuron.m @@ -92,7 +92,7 @@ end end % If no neuron was found - if isempty(neuronLabels) + if isempty(labelsNeurons) bst_report('Error', sProcess, sCurrentInputs(1), 'No neurons/spiking events detected.'); return; end diff --git a/toolbox/process/functions/process_rasterplot_per_neuron.m b/toolbox/process/functions/process_rasterplot_per_neuron.m index e83a32254..ee6ec9718 100644 --- a/toolbox/process/functions/process_rasterplot_per_neuron.m +++ b/toolbox/process/functions/process_rasterplot_per_neuron.m @@ -82,7 +82,7 @@ end end % If no neuron was found - if isempty(neuronLabels) + if isempty(labelsNeurons) bst_report('Error', sProcess, sCurrentInputs(1), 'No neurons/spiking events detected.'); return; end diff --git a/toolbox/process/functions/process_spike_triggered_average.m b/toolbox/process/functions/process_spike_triggered_average.m index 14de1da56..5e29d4308 100644 --- a/toolbox/process/functions/process_spike_triggered_average.m +++ b/toolbox/process/functions/process_spike_triggered_average.m @@ -165,7 +165,7 @@ end end % Divide by total number of averages - STA_single_neuron = (STA_single_neuron./divideBy)'; + STA_single_neuron = (STA_single_neuron./divideBy); % std_single_neuron = sqrt(std_single_neuron./(divideBy - size(all_labels,2))); % Get meaningful label from neuron name @@ -179,7 +179,7 @@ % ===== SAVE FILE ===== % Prepare output file structure FileMat = db_template('datamat'); - FileMat.F = STA_single_neuron'; + FileMat.F = STA_single_neuron; FileMat.Time = time_segmentAroundSpikes; % FileMat.Std = 2 .* std_single_neuron; % MULTIPLY BY 2 TO GET 95% CONFIDENCE (ASSUMING NORMAL DISTRIBUTION) FileMat.Comment = ['Spike Triggered Average: ' str_remove_parenth(DataMats{1}.Comment) ' (' better_label ')'];