-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfear_coact_within_oscillation.m
117 lines (95 loc) · 3.37 KB
/
fear_coact_within_oscillation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
function fear_coact_within_oscillation(basename,varargin)
% basename='~/data/Fear/triple/hoegaarden181115/hoegaarden181115';
%%
load([basename '.basicMetaData.mat'])
fprintf('%s start %s with data of %s\n',datestr(now),mfilename,basicMetaData.SessionName)
%%
param.templateSes=2;
param.targetHC=3;
param.tRange=0.1;
param=parseParameters(param,varargin);
%%
load([basicMetaData.Basename '.SleepState.states.mat'])
load([basicMetaData.Basename '.sessions.events.mat'])
if exist([basicMetaData.Basename '.ripples.events.mat'],'file')
load([basicMetaData.Basename '.ripples.events.mat'])
else
ripples.peaks.timestamps=[];
end
load([basicMetaData.Basename '.amyHFO.events.mat'])
load([basicMetaData.Basename '.pfcRipple.events.mat'])
temp=matfile([basicMetaData.AnalysesName '-icaReac.mat']);
icaReac=temp.icaReac(1,param.templateSes);
temp=matfile([basicMetaData.AnalysesName '-icaReacZNCCG_sig.mat']);
icaSig=temp.icaReacZNCCG_sig(1,param.templateSes);
temp=matfile([basicMetaData.AnalysesName '-icaReacZNCCG.mat']);
znccg=temp.icaReacZNCCG(1,param.templateSes);
zReac=zscore(icaReac.strength,[],2);
tBin=((1:size(zReac,2))-0.5)*0.02;
slp=relabel_ma2sleep(SleepState.MECE.timestamps);
%%
subNrem=slp(slp(:,2)>sessions.homecage(param.targetHC,1) & slp(:,1)<sessions.homecage(param.targetHC,2) & slp(:,3)==3,1:2);
%%
for evtType=1:3
switch evtType
case 1
evtT=ripples.peaks.timestamps;
evtName='SWR';
case 2
evtT=amyHFO.peaks.timestamps;
evtName='HFO';
case 3
evtT=pfcRipple.peaks.timestamps;
evtName='cRipple';
end
if ~isempty(evtT)
evtT=evtT(...
evtT>sessions.homecage(3,1) &...
evtT<sessions.homecage(3,2));
end
if ~isempty(evtT)
evtT=evtT(any(evtT>subNrem(:,1)' & evtT<subNrem(:,2)',2));
end
trigBin.(evtName)=round(evtT/0.02);
end
%%
evtList=fieldnames(trigBin);
for evtIdx=1:length(evtList)
evtName=evtList{evtIdx};
nHalfBin=round(param.tRange/0.02);
y=zeros(2*nHalfBin+1,length(trigBin.(evtName)),size(zReac,1));
if ~isempty(y)
for n=1:size(zReac,1)
x=zReac(n,:);
y(:,:,n)=x(trigBin.(evtName)+(-nHalfBin:nHalfBin))';
end
end
avg=zeros(1,size(zReac,1));
err=zeros(1,size(zReac,1));
for n=1:size(zReac,1)
temp=y(:,:,n);
avg(n)=mean(temp(:));
err(n)=std(temp(:));
end
r=zeros(size(icaSig.pairID,1),2*nHalfBin+1);
for n=1:size(icaSig.pairID,1)
tempR=zeros(2*nHalfBin+1,1);
for m=1:size(y,2)
tempR=tempR+xcorr(y(:,m,icaSig.pairID(n,1)),y(:,m,icaSig.pairID(n,2)),nHalfBin);
end
r(n,:)=(tempR/size(y,2)/(2*nHalfBin+1)-avg(icaSig.pairID(n,1))*avg(icaSig.pairID(n,2))) / ...
(err(icaSig.pairID(n,1))*err(icaSig.pairID(n,2)));
end
icaZNCCG_withinEvt.(evtName).znccg=r;
icaZNCCG_withinEvt.(evtName).mean=avg;
icaZNCCG_withinEvt.(evtName).std=err;
icaZNCCG_withinEvt.(evtName).nEvt=size(y,2);
end
icaZNCCG_withinEvt.pairID = icaSig.pairID;
icaZNCCG_withinEvt.region = icaSig.region;
icaZNCCG_withinEvt.template = icaSig.template;
icaZNCCG_withinEvt.param=param.tRange;
icaZNCCG_withinEvt.generator=mfilename;
icaZNCCG_withinEvt.generatedate=datestr(now,'yyyy-mm-dd');
save([basicMetaData.AnalysesName '-icaZNCCG_withinEvt.mat'],'icaZNCCG_withinEvt','-v7.3')
%%