diff --git a/BARRs/BARR_PSTH.m b/BARRs/BARR_PSTH.m index 9f86aa5..b386acf 100644 --- a/BARRs/BARR_PSTH.m +++ b/BARRs/BARR_PSTH.m @@ -225,9 +225,9 @@ function BARR_PSTH(plotSave,useState) if plotRips % PSTH_ripples = computePSTH(ripples,spikes,'duration',1,'plots', false,'alignment','peaks','zscorePlot',false); % [PSTH_ripples,PSTH_t] = makePETH(spikes,ripples.timestamps(:,1),[-3 3]); - [PSTH_ripples, PSTH_t] = manualPSTH(spikes, ripples.timestamps(:,1),[-1,1],1/1000); + [PSTH_ripples, PSTH_t] = manualPSTH(spikes, ripples.timestamps(:,1),[-1,1],1/100); %was 1/1000 if runTags - warning('NOT ADJUSTED TO NEW DIMENSIONS'); + %warning('NOT ADJUSTED TO NEW DIMENSIONS'); % for k = 1:size(PSTH_ripples,1) % if ((max(PSTH_ripples(k,91:111))-max(PSTH_ripples(k,1:71))) > 1.5*std(PSTH_ripples(k,:))) % cell_metrics.tags.Pr = [cell_metrics.tags.Pr spikes.UID(k)]; @@ -248,9 +248,9 @@ function BARR_PSTH(plotSave,useState) end % PSTH_bar = computePSTH(HSEnrem,spikes,'duration',1,'plots', false,'alignment','peaks','zscorePlot',false); % [PSTH_bar,PSTH_t] = makePETH(spikes,HSEuse.timestamps(:,1),[-3 3]); - [PSTH_bar, PSTH_t] = manualPSTH(spikes, HSEuse.timestamps(:,1),[-1 1],1/1000); + [PSTH_bar, PSTH_t] = manualPSTH(spikes, HSEuse.timestamps(:,1),[-1 1],1/100); %was 1/1000 if runTags - warning('NOT ADJUSTED TO NEW DIMENSIONS'); + %warning('NOT ADJUSTED TO NEW DIMENSIONS'); % for k = 1:size(PSTH_bar,1) % if (mean(PSTH_bar(k,1001:2001))-mean(PSTH_bar(k,1:100))) > 0.3 % cell_metrics.tags.Pb = [cell_metrics.tags.Pb spikes.UID(k)]; @@ -414,7 +414,7 @@ function BARR_PSTH(plotSave,useState) shuffled_r = cumsum([shuffled_iri]); %raly had cumsum([0; shuffled_iri]); [ccg_ripple_barrage_shuf,t_ripple_barrage_shuf] = CCG(cat(1,shuffled_r,t_barrages{1}),cat(1,t_ripple_id{1},2*t_barrage_id{1}),'binSize',binsize,'duration',duration,'norm','rate'); - figure(5);plot(t_ripple_barrage_shuf,ccg_ripple_barrage_shuf(:,2,1),'r');hold on;title('ccg barr-SWR'); yline(0,'k--');xlim([-3 3]); + figure(5);plot(t_ripple_barrage_shuf,ccg_ripple_barrage_shuf(:,2,1),'r');hold on;title('ccg barr-SWR shuffle'); yline(0,'k--');xlim([-3 3]); saveas(gcf,[plotSave 'CCG_shuff.png']); % Old jitter start % for it = 1:10000 diff --git a/BARRs/detectBARR.m b/BARRs/detectBARR.m index a217fdc..6631e76 100644 --- a/BARRs/detectBARR.m +++ b/BARRs/detectBARR.m @@ -53,12 +53,14 @@ % Default: 0 % pareDur: Minimum duration of BARRs kept, in seconds. This should % generally be kept at or below 0.2. Default: 0.2 -% zeroRip: Logical option to zero firing during SWRs. This is -% typically used for sessions containing stimulation (ie -% ripple generation). This seems to be a better option than -% remRip.Default: false -% remRip: Logical option to remove BARRs which overlap with ripples. +% zeroRip: Logical option to remove BARRs which overlap with ripples. +% This seems to be a better option than remRip. % Default: false +% remRip: Logical option to zero firing during SWRs. This is +% typically used for sessions containing stimulation (ie +% ripple generation). Default: false +% newSpks: Logical option to regenerate spike groups if the regions or +% cell types have been adjusted. Default: false % %%%%%%%%%%%%%%% %%% OUTPUTS %%% @@ -101,6 +103,7 @@ addParameter(p, 'pareDur', 0.2, @isnumeric); addParameter(p, 'zeroRip', true, @islogical); addParameter(p, 'remRip', false, @islogical); +addParameter(p, 'newSpks', false, @islogical); parse(p, varargin{:}); @@ -118,6 +121,7 @@ pareDur = p.Results.pareDur; zeroRip = p.Results.zeroRip; remRip = p.Results.remRip; +newSpks = p.Results.newSpks; %% Check if BARRs have already been detected basename = basenameFromBasepath(basepath); @@ -135,7 +139,7 @@ mkdir([basepath filesep 'Barrage_Files']); end -pullSpikes('basepath', basepath, 'savePath', [basepath filesep 'Barrage_Files'], 'force', true); %Get region/cell type spike files +pullSpikes('basepath', basepath, 'savePath', [basepath filesep 'Barrage_Files'], 'force', newSpks); %Get region/cell type spike files if ~exist(strcat(basepath,filesep,'Barrage_Files',filesep,basename,'.CA2pyr.cellinfo.mat')) disp('No CA2 pyramidal cells detected, exiting'); @@ -174,6 +178,12 @@ 'recordMetrics',true,'remRip',remRip); HSE = pareBARRs(basepath, HSE, spikes, savePath, unMin, spkNum, pareDur, spkHz, zeroRip, unMax); +%add unitsForDetection parameters +HSE.detectorinfo.Hz = Hz; +HSE.detectorinfo.ft = ft; +HSE.detectorinfo.numEvt = numEvt; +HSE.detectorinfo.savePath = savePath; +save([savePath 'HSE.mat'], 'HSE'); %% Save NeuroScope2 file BARR_N2(basepath); diff --git a/BARRs/pareBARRs.m b/BARRs/pareBARRs.m index 58a56b1..23caa21 100644 --- a/BARRs/pareBARRs.m +++ b/BARRs/pareBARRs.m @@ -136,5 +136,14 @@ HSE.fin = HSE.keep(HSE.NREM(HSE.nonRip)); disp(['Final num: ' num2str(length(HSE.fin))]); disp(['Num removed: ' num2str(length(HSE.NREM) - length(HSE.fin))]); + +%%add parameters +HSE.detectorinfo.numCell = numCell; +HSE.detectorinfo.numSpk = numSpk; +HSE.detectorinfo.pareDur = pareDur; +HSE.detectorinfo.singleHz = singleHz; +HSE.detectorinfo.stim = stim; +HSE.detectorinfo.maxCell = maxCell; + save([savePath 'HSE.mat'], 'HSE'); end \ No newline at end of file diff --git a/BARRs/pullSpikes.m b/BARRs/pullSpikes.m index db186aa..08929fc 100644 --- a/BARRs/pullSpikes.m +++ b/BARRs/pullSpikes.m @@ -16,7 +16,7 @@ function pullSpikes(varargin) addParameter(p,'savePath',pwd,@ischar); addParameter(p,'force',false,@islogical); -parse(p,varargin{:}) +parse(p, varargin{:}); basepath = p.Results.basepath; savePath = p.Results.savePath; @@ -27,8 +27,8 @@ function pullSpikes(varargin) basename = basenameFromBasepath(basepath); %% Remove old runs if necessary +getFiles = dir(); if force - getFiles = dir(); fun_existsPyr = @(x) (contains(x, 'pyr.cellinfo.mat')); fun_existsInt = @(x) (contains(x, 'int.cellinfo.mat')); toDelete = zeros(size(getFiles,1),1); @@ -53,6 +53,7 @@ function pullSpikes(varargin) fun_existsInt = @(x) (contains(x, 'int.cellinfo.mat')); for j = 1:size(getFiles,1) if fun_existsPyr(getFiles(j).name)||fun_existsInt(getFiles(j).name) + cd(original); disp('Region spike structures detected, returning'); return end