-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMS_load_data.m
More file actions
222 lines (190 loc) · 10.9 KB
/
Copy pathMS_load_data.m
File metadata and controls
222 lines (190 loc) · 10.9 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
function [data, cfg] = MS_load_data(cfg_in)
%% MS_load_data:
% used to load the raw LFP recodings across multiple subject and segragate
% the data into the different phases ('pre', 'ipsi', 'contra', 'post') as
% well as pot vs track segments
%
% inputs:
% global PARAMS from MASTER_Multisite
% - cfg_in: input configuration
%
%
% outputs:
% - data [struct]: contains data for each subjects separated into
% session(day), phases(pre, ipsi, contra, post), segments(pot, trk)
% -cfg_out [struct]: contains the configurations use to process the data
%% Initial paramters
global PARAMS
cfg_def = [];
cfg= ProcessConfig2(cfg_def, cfg_in);
%% load the data fpr each phase within the session.
for iPhase = 1:length(PARAMS.Phases)
if isunix
cd([PARAMS.data_dir '/' cfg.fname(1:4) '/' cfg.fname '/' cfg.fname '_' PARAMS.Phases{iPhase}])
else
cd([PARAMS.data_dir '\' cfg.fname(1:4) '\' cfg.fname '\' cfg.fname '_' PARAMS.Phases{iPhase}])
end
LoadExpKeys()
evt= LoadEvents([]);
% check to see if I was dumb and didnt stop recording between the pot
% and track. If so, then split the session in half shave off 1/10 of
% off the end for the first half and the start of the second.
idx = strfind(evt.label, 'Starting Recording');
start_idx = find(not(cellfun('isempty', idx)));
idx = strfind(evt.label, 'Stopping Recording');
stop_idx = find(not(cellfun('isempty', idx)));
% check to make sure NLX didn't mess up the start stop events (this
% happened for R104-2016-09-26_ipsi. It has 19 start times for some
% reason)
if length(evt.t{start_idx}) >= 3 % should only have 2
[~, trk_idx] = max(diff(evt.t{start_idx}(2:end))); % find the largest gap
trk_idx = trk_idx +1; % offset by one to compensate for the "diff"
else
trk_idx = [];
end
% subjects with only OFC, NAc, CG.
if strcmp(ExpKeys.ratID, 'R547606') || strcmp(ExpKeys.ratID, 'R547576') || strcmp(ExpKeys.ratID, 'R547574')
cfg_load = [];
cfg_load.fc = ExpKeys.Chan_to_use(1);
OFC_csc = LoadCSC(cfg_load);
OFC_csc.data_label = ExpKeys.Chan_to_use_labels{1};
cfg_load.fc = ExpKeys.Chan_to_use(2);
NAc_csc = LoadCSC(cfg_load);
NAc_csc.data_label = ExpKeys.Chan_to_use_labels{2};
cfg_load.fc = ExpKeys.Chan_to_use(3);
CG_csc = LoadCSC(cfg_load);
CG_csc.data_label = ExpKeys.Chan_to_use_labels{3};
% collect the data
% data.(PARAMS.Phases{iPhase}).OFC = OFC_csc;
% data.(PARAMS.Phases{iPhase}).NAc = NAc_csc;
% data.(PARAMS.Phases{iPhase}).CG = CG_csc;
% split into pot and track.
data.(PARAMS.Phases{iPhase}).OFC_pot = restrict(OFC_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).NAc_pot = restrict(NAc_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).CG_pot = restrict(CG_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
collect the data
data.(PARAMS.Phases{iPhase}).OFC_trk = restrict(OFC_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).NAc_trk = restrict(NAc_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).CG_trk = restrict(CG_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
% subjects with PL, OFC, NAc, CG
elseif strcmp(ExpKeys.ratID, 'R547607') || strcmp(ExpKeys.ratID, 'R547577') || strcmp(ExpKeys.ratID, 'R104')
cfg_load = [];
% get the PL
cfg_load.fc = ExpKeys.Chan_to_use(1);
PL_csc = LoadCSC(cfg_load);
PL_csc.data_label = ExpKeys.Chan_to_use_labels{1};
% get the OFC
cfg_load.fc = ExpKeys.Chan_to_use(2);
OFC_csc = LoadCSC(cfg_load);
OFC_csc.data_label = ExpKeys.Chan_to_use_labels{2};
% get the NAc
cfg_load.fc = ExpKeys.Chan_to_use(3);
NAc_csc = LoadCSC(cfg_load);
NAc_csc.data_label = ExpKeys.Chan_to_use_labels{3};
%
cfg_load.fc = ExpKeys.Chan_to_use(4);
CG_csc = LoadCSC(cfg_load);
CG_csc.data_label = ExpKeys.Chan_to_use_labels{4};
% split into pot and track.
data.(PARAMS.Phases{iPhase}).OFC_pot = restrict(OFC_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).NAc_pot = restrict(NAc_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).CG_pot = restrict(CG_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).PL_pot = restrict(PL_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
% collect the data
if isempty(trk_idx)
data.(PARAMS.Phases{iPhase}).OFC_trk = restrict(OFC_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).NAc_trk = restrict(NAc_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).CG_trk = restrict(CG_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).PL_trk = restrict(PL_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
else
data.(PARAMS.Phases{iPhase}).OFC_trk = restrict(OFC_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).NAc_trk = restrict(NAc_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).CG_trk = restrict(CG_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).PL_trk = restrict(PL_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
end
% PL, NAc, CG, and piriform cortex (PC).
elseif strcmp(ExpKeys.ratID, 'R102')
cfg_load = [];
% get the PL
cfg_load.fc = ExpKeys.Chan_to_use(1);
PL_csc = LoadCSC(cfg_load);
PL_csc.data_label = ExpKeys.Chan_to_use_labels{1};
% get the OFC
cfg_load.fc = ExpKeys.Chan_to_use(2);
PC_csc = LoadCSC(cfg_load);
PC_csc.data_label = ExpKeys.Chan_to_use_labels{2};
% get the NAc
cfg_load.fc = ExpKeys.Chan_to_use(3);
NAc_csc = LoadCSC(cfg_load);
NAc_csc.data_label = ExpKeys.Chan_to_use_labels{3};
%
cfg_load.fc = ExpKeys.Chan_to_use(4);
CG_csc = LoadCSC(cfg_load);
CG_csc.data_label = ExpKeys.Chan_to_use_labels{4};
% split into pot and track.
data.(PARAMS.Phases{iPhase}).PC_pot = restrict(PC_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).NAc_pot = restrict(NAc_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).CG_pot = restrict(CG_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).PL_pot = restrict(PL_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
% collect the data
if isempty(trk_idx)
data.(PARAMS.Phases{iPhase}).PC_trk = restrict(PC_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).NAc_trk = restrict(NAc_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).CG_trk = restrict(CG_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).PL_trk = restrict(PL_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
else
data.(PARAMS.Phases{iPhase}).PC_trk = restrict(PC_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).NAc_trk = restrict(NAc_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).CG_trk = restrict(CG_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).PL_trk = restrict(PL_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
end
elseif strcmp(ExpKeys.ratID, 'R122') || strcmp(ExpKeys.ratID, 'R123')
cfg_load = [];
% get the Piri_OFC
cfg_load.fc = ExpKeys.Chan_to_use(1);
Piri_OFC_csc = LoadCSC(cfg_load);
Piri_OFC_csc.data_label = ExpKeys.Chan_to_use_labels{1};
% get the OFC
cfg_load.fc = ExpKeys.Chan_to_use(2);
OFC_csc = LoadCSC(cfg_load);
OFC_csc.data_label = ExpKeys.Chan_to_use_labels{2};
% get the NAc
cfg_load.fc = ExpKeys.Chan_to_use(3);
NAc_csc = LoadCSC(cfg_load);
NAc_csc.data_label = ExpKeys.Chan_to_use_labels{3};
% get the Piri_NAc
cfg_load.fc = ExpKeys.Chan_to_use(4);
Piri_NAc_csc = LoadCSC(cfg_load);
Piri_NAc_csc.data_label = ExpKeys.Chan_to_use_labels{4};
%CG
cfg_load.fc = ExpKeys.Chan_to_use(5);
CG_csc = LoadCSC(cfg_load);
CG_csc.data_label = ExpKeys.Chan_to_use_labels{5};
% split into pot and track.
data.(PARAMS.Phases{iPhase}).Piri_OFC_pot = restrict(Piri_OFC_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).OFC_pot = restrict(OFC_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).NAc_pot = restrict(NAc_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).CG_pot = restrict(CG_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).Piri_NAc_pot = restrict(Piri_NAc_csc,evt.t{start_idx}(1),evt.t{stop_idx}(1));
% collect the data
if isempty(trk_idx)
data.(PARAMS.Phases{iPhase}).Piri_OFC_trk = restrict(Piri_OFC_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).OFC_trk = restrict(OFC_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).NAc_trk = restrict(NAc_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).CG_trk = restrict(CG_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).Piri_NAc_trk = restrict(Piri_NAc_csc,evt.t{start_idx}(2),evt.t{stop_idx}(2));
else
data.(PARAMS.Phases{iPhase}).Piri_OFC_trk = restrict(Piri_OFC_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).OFC_trk = restrict(OFC_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).NAc_trk = restrict(NAc_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).CG_trk = restrict(CG_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
data.(PARAMS.Phases{iPhase}).Piri_NAc_trk = restrict(Piri_NAc_csc,evt.t{start_idx}(trk_idx),evt.t{stop_idx}(trk_idx));
end
end
% get the position for each phase
cfg_load = [];
pos = LoadPos(cfg_load);
data.(PARAMS.Phases{iPhase}).pos.pot = restrict(pos,evt.t{start_idx}(1),evt.t{stop_idx}(1));
data.(PARAMS.Phases{iPhase}).pos.trk = restrict(pos,evt.t{start_idx}(2),evt.t{stop_idx}(2));
data.(PARAMS.Phases{iPhase}).ExpKeys = ExpKeys;
end