|
3 | 3 | %align number of rows of population data
|
4 | 4 |
|
5 | 5 | %% get ready
|
| 6 | +limSuffix = '';%'_woSuccess';%_woSuccess'; |
| 7 | + |
6 | 8 | [saveServer, rootFolder] = getReady();
|
7 |
| -saveSuffix_p = 'fitPSTH_pop20231102'; |
| 9 | +saveSuffix_p = ['fitPSTH_pop' limSuffix]; |
8 | 10 |
|
9 | 11 | %% recorded data
|
10 | 12 | animal = 'hugo';
|
11 | 13 | dataType = 0;%0: each channel, 1: all channels per day
|
12 | 14 | tWin = [0 0.5];%[s]
|
13 | 15 |
|
14 |
| -load(fullfile(saveServer,'param20231102.mat'),'param'); |
15 |
| - |
16 | 16 | %alldata = [];
|
17 | 17 | mFiringRate_pop = [];
|
18 | 18 | kernel_pop = [];
|
|
30 | 30 | id_pop = [];
|
31 | 31 | Rsqadj_pop = [];
|
32 | 32 | gainInfo_pop = [];
|
| 33 | +expval_trig_pop = []; |
| 34 | +corr_trig_pop = []; |
33 | 35 | errorIDs= cell(1);
|
34 |
| -for yy = 1:3 |
| 36 | +for yy = 1%:3 |
35 | 37 | switch yy
|
36 | 38 | case 1
|
37 | 39 | year = '2021';
|
|
54 | 56 | %dataByYear = [];%struct(length(channels),1);
|
55 | 57 | %datech_pop = nan(length(channels),1);
|
56 | 58 | %corrcoef_pred_spk_pop = nan(length(channels),1);
|
57 |
| - for idata = 1:length(channels) |
| 59 | + for idata = 1:150%length(channels) |
58 | 60 | datech = [months{idata} '/' dates{idata} '/' num2str(channels{idata})];
|
59 | 61 | thisid = [animal '/' year '/' datech];
|
60 | 62 | disp(thisid);
|
61 | 63 |
|
62 |
| - saveSuffix = [animal replace(datech,'/','_') '_linear_rReg']; |
| 64 | + saveSuffix = [animal replace(datech,'/','_') '_linear_rReg' limSuffix]; |
63 | 65 |
|
64 | 66 | thisDate = [months{idata} '_' dates{idata}];
|
65 | 67 |
|
|
73 | 75 | S = load(saveName, 'PSTH_f','predicted_all', 'predicted', ...
|
74 | 76 | 'kernelInfo','t_r','cellclassInfo','param','mFiringRate','t_cat',...
|
75 | 77 | 'dds');
|
76 |
| - |
77 |
| - |
| 78 | + |
78 | 79 | if isfield(S,'kernelInfo')
|
79 | 80 | mFiringRate_pop = cat(2,mFiringRate_pop,S.mFiringRate);
|
80 | 81 | kernel_pop = cat(3,kernel_pop,S.kernelInfo.kernel);
|
|
88 | 89 |
|
89 | 90 | eyeName = fullfile(saveFolder,[
|
90 | 91 | 'eyeCat_' animal thisDate '.mat']);
|
91 |
| - load(fullfile(saveFolder,['predictorInfo_' animal thisDate '.mat']), ... |
92 |
| - 'predictorInfo'); |
93 |
| - load(eyeName,'eyeData_rmotl_cat','catEvTimes'); |
94 |
| - |
95 |
| - if ~isfield(S,'dds') |
96 |
| - load(loadNames{idata},'dd'); %slow to read |
97 |
| - dds = getCueSaccadeSmall(dd); |
98 |
| - save(saveName, 'dds','-append'); |
99 |
| - S.dds = dd; |
100 |
| - end |
101 |
| - dd = S.dds; |
| 92 | + % load(fullfile(saveFolder,['predictorInfo_' animal thisDate '.mat']), ... |
| 93 | + % 'predictorInfo'); |
| 94 | + load(eyeName,'eyeData_rmotl_cat','catEvTimes','startSaccNoTask'); |
102 | 95 |
|
| 96 | + % if ~isfield(S,'dds') |
| 97 | + load(loadNames{idata},'dd'); %slow to read |
| 98 | + % dds = getCueSaccadeSmall(dd); |
| 99 | + % save(saveName, 'dds','-append'); |
| 100 | + % S.dds = dd; |
| 101 | + % end |
| 102 | + % dd = S.dds; |
103 | 103 |
|
104 |
| - %% Rsq adj of subjset of variables |
105 |
| - nsub=4; |
106 |
| - Rsqadj = zeros(nsub,1); |
107 |
| - for jj = 1:nsub |
108 |
| - switch jj |
109 |
| - case 1 %full model |
110 |
| - tgtGroups = 1:5; |
111 |
| - case 2 %omit vision %added 26/10/2023 |
112 |
| - tgtGroups = setxor(1:5, 1); |
113 |
| - case 3 %omit eye speed |
114 |
| - tgtGroups = setxor(1:5, 2); |
115 |
| - case 4 %omit eye position |
116 |
| - tgtGroups = setxor(1:5, 3); |
117 |
| - end |
118 |
| - [Rsqadjusted,rr,r0] = fitSubset(S.PSTH_f, predictorInfo, ... |
119 |
| - tgtGroups, param);%, idxTgtOnsets); |
120 | 104 |
|
121 |
| - Rsqadj(jj) = Rsqadjusted; |
122 |
| - end |
123 |
| - Rsqadj_pop = [Rsqadj_pop Rsqadj]; |
| 105 | + %% Rsq adj of subjset of variables |
| 106 | + % nsub=4; |
| 107 | + % Rsqadj = zeros(nsub,1); |
| 108 | + % for jj = 1:nsub |
| 109 | + % switch jj |
| 110 | + % case 1 %full model |
| 111 | + % tgtGroups = 1:5; |
| 112 | + % case 2 %omit vision %added 26/10/2023 |
| 113 | + % tgtGroups = setxor(1:5, 1); |
| 114 | + % case 3 %omit eye speed |
| 115 | + % tgtGroups = setxor(1:5, 2); |
| 116 | + % case 4 %omit eye position |
| 117 | + % tgtGroups = setxor(1:5, 3); |
| 118 | + % end |
| 119 | + % [Rsqadjusted,rr,r0] = fitSubset(S.PSTH_f, predictorInfo, ... |
| 120 | + % tgtGroups, param);%, idxTgtOnsets); |
| 121 | + % |
| 122 | + % Rsqadj(jj) = Rsqadjusted; |
| 123 | + % end |
| 124 | + % Rsqadj_pop = [Rsqadj_pop Rsqadj]; |
124 | 125 |
|
125 | 126 | % %Rsq_adjusted computed from pre-target
|
126 | 127 | % periods - NG. can be < 0
|
|
135 | 136 | % Rsqadj_tgt_pop = [Rsqadj_tgt_pop Rsqadjusted_tgt];
|
136 | 137 |
|
137 | 138 | %% response to target
|
138 |
| - PtonsetResp_pop = [PtonsetResp_pop S.cellclassInfo.PtonsetResp]; |
139 |
| - |
140 |
| - %% response to saccade |
141 |
| - PsaccResp_pop = [PsaccResp_pop S.cellclassInfo.PsaccResp]; |
| 139 | + %PtonsetResp_pop = [PtonsetResp_pop S.cellclassInfo.PtonsetResp]; |
| 140 | + |
| 141 | + % %% response to saccade |
| 142 | + % PsaccResp_pop = [PsaccResp_pop S.cellclassInfo.PsaccResp]; |
142 | 143 |
|
143 | 144 | %% explained variance per kernel
|
144 | 145 | expval = zeros(size(S.predicted,2)+1,1);
|
|
152 | 153 |
|
153 | 154 | %% explained variance for target response
|
154 | 155 | expval_tgt(1,1) = getExpVal_tgt(S.PSTH_f, S.predicted_all, catEvTimes, S.t_r, tWin);
|
155 |
| - expval_tgt(2:6,1) = getExpVal_tgt(S.PSTH_f, S.predicted, catEvTimes, S.t_r, tWin); |
| 156 | + expval_tgt(2:7,1) = getExpVal_tgt(S.PSTH_f, S.predicted, catEvTimes, S.t_r, tWin); |
156 | 157 |
|
157 | 158 | expval_tgt_pop = [expval_tgt_pop expval_tgt];
|
158 | 159 |
|
|
164 | 165 | % expval_avgtgt_pop = [expval_avgtgt_pop expval_avgtgt];
|
165 | 166 | % corr_avgtgt_pop = [corr_avgtgt_pop corr_avgtgt];
|
166 | 167 |
|
| 168 | + %% compute time-resolved explained variance |
| 169 | + [choiceOutcome] = getChoiceOutcome(dd); |
| 170 | + |
| 171 | + expval_trig = []; corr_trig = []; |
| 172 | + for ievtype = 1:4 |
| 173 | + % 1: success trial |
| 174 | + % 2: failed quiescent trial |
| 175 | + % 3: failed wrong saccade direction |
| 176 | + % 4: saccade outside trials |
| 177 | + |
| 178 | + if ievtype <= 3 |
| 179 | + theseEvents = find(choiceOutcome==ievtype); |
| 180 | + eventTimes = catEvTimes.tOnset(theseEvents); |
| 181 | + elseif ievtype == 4 |
| 182 | + eventTimes = startSaccNoTask; |
| 183 | + end |
| 184 | + [expval_trig(:,:,ievtype), corr_trig(:,:,ievtype), winSamps] = ... |
| 185 | + getExpVal_trig(S.PSTH_f, [S.predicted_all S.predicted], S.t_r, eventTimes, [-0.5 0.5]); |
| 186 | + |
| 187 | + %ax_expval_trig(ievtype) = subplot(4,1,ievtype); |
| 188 | + %plot(winSamps, squeeze(expval_trig(:,:,ievtype))'); |
| 189 | + end |
| 190 | + expval_trig_pop = cat(4, expval_trig_pop, expval_trig); |
| 191 | + corr_trig_pop = cat(4, corr_trig_pop, expval_trig); |
| 192 | + |
167 | 193 | %% number of target trials
|
168 | 194 | ntargetTrials_pop = [ntargetTrials_pop sum(~isnan(catEvTimes.tOnset))];
|
169 | 195 |
|
|
175 | 201 | onlySuccess = 0;
|
176 | 202 | respWin = [0.05 0.35]; %[s]
|
177 | 203 | y_r = cat(2,S.PSTH_f,S.predicted_all);
|
178 |
| - gainInfo = getGainInfo(S.t_r, y_r, param.cardinalDir, catEvTimes, ... |
| 204 | + gainInfo = getGainInfo(S.t_r, y_r, S.param.cardinalDir, catEvTimes, ... |
179 | 205 | dd, figTWin, onlySuccess, respWin);
|
180 | 206 | gainInfo_pop = [gainInfo_pop gainInfo];
|
181 | 207 |
|
182 | 208 | %retrieve just once
|
183 | 209 | tlags = S.kernelInfo.tlags;
|
| 210 | + param = S.param; |
| 211 | + |
184 | 212 | clear S
|
185 | 213 | end
|
186 | 214 | catch err
|
187 | 215 | errorIDs{numel(errorIDs)+1} = thisid;
|
188 |
| - continue; |
| 216 | + disp('ERROR'); |
| 217 | + %continue; |
189 | 218 | end
|
190 | 219 | end
|
191 | 220 | end
|
|
195 | 224 |
|
196 | 225 | % save('fitPSTH_pop20220202','avgPupilResp_pop', '-append');
|
197 | 226 | kernel_pop = squeeze(kernel_pop);
|
198 |
| -save(fullfile(saveServer,saveSuffix_p,[saveSuffix_p animal]),'mFiringRate_pop','kernel_pop','expval_pop','corrcoef_pop',... |
| 227 | +save(fullfile(saveServer,[saveSuffix_p animal '.mat']),'mFiringRate_pop','kernel_pop','expval_pop','corrcoef_pop',... |
199 | 228 | 'corrcoef_pred_spk_pop','id_pop','ntotTrials_pop','ntargetTrials_pop','param',...
|
200 | 229 | 'PsaccResp_pop','PtonsetResp_pop','expval_ind_pop','expval_tgt_pop','tlags',...
|
201 |
| - 'corr_avgtgt_pop','expval_avgtgt_pop','Rsqadj_pop','gainInfo_pop'); |
| 230 | + 'corr_avgtgt_pop','expval_avgtgt_pop','gainInfo_pop','expval_trig_pop','corr_trig_pop','winSamps'); %'Rsqadj_pop', |
| 231 | + |
| 232 | +% from syncitium/Daisuke/cuesaccade_data OBS/param20231102.mat |
| 233 | +param.mfiringRateTh = 5; |
| 234 | +param.expvalTh = 3; |
| 235 | +param.ntargetTrTh = 200; |
| 236 | +param.ptonsetRespTh = 0.05; |
202 | 237 |
|
203 | 238 | %% apply inclusion critetia
|
204 | 239 | % [okunits, mfiringRateOK, expvalOK, ntargetTrOK, ptonsetRespOK] ...
|
205 | 240 | % = inclusionCriteria(mFiringRate_pop, expval_pop, ntargetTrials_pop, PtonsetResp_pop, param);
|
206 | 241 | % [okunits, mfiringRateOK, expvalOK, ntargetTrOK, ptonsetRespOK] ...
|
207 | 242 | % = inclusionCriteria(mFiringRate_pop, expval_tgt_pop(1,:), ntargetTrials_pop, PtonsetResp_pop, param);
|
208 |
| -[okunits, mfiringRateOK, expvalOK, ntargetTrOK, ptonsetRespOK] ... |
209 |
| - = inclusionCriteria(mFiringRate_pop, expval_ind_pop(1,:), ntargetTrials_pop, PtonsetResp_pop, param); |
| 243 | +% [okunits, mfiringRateOK, expvalOK, ntargetTrOK, ptonsetRespOK] ... |
| 244 | +% = inclusionCriteria(mFiringRate_pop, expval_ind_pop(1,:), ntargetTrials_pop, PtonsetResp_pop, param); |
| 245 | + |
| 246 | +%TEMP as PtonsetResp_pop is unavailable: |
| 247 | +okunits = find((mFiringRate_pop>param.mfiringRateTh) ... |
| 248 | + + (expval_ind_pop(1,:)>param.expvalTh) ... |
| 249 | + + (ntargetTrials_pop> param.ntargetTrTh) == 3); |
| 250 | +save(fullfile(saveServer,[saveSuffix_p animal '.mat']), 'okunits','-append'); |
210 | 251 |
|
211 |
| -%% hack exclude redundant data |
212 |
| -[~, mfiringRate_u] = unique(mFiringRate_pop); |
213 |
| -[~, expval_u] = unique(expval_ind_pop(1,:)); |
214 |
| -okunits_u = intersect(mfiringRate_u, expval_u); |
215 |
| -okunits = intersect(okunits, okunits_u); |
216 | 252 |
|
217 | 253 | kernel_pop = kernel_pop(:,okunits);
|
218 | 254 | expval_ind_pop = expval_ind_pop(:,okunits);
|
|
221 | 257 | %corr_avgtgt_pop = corr_avgtgt_pop(:,okunits);
|
222 | 258 | id_pop = id_pop(okunits);
|
223 | 259 | mFiringRate_pop = mFiringRate_pop(okunits);
|
224 |
| -Rsqadj_pop = Rsqadj_pop(:,okunits); |
| 260 | +%Rsqadj_pop = Rsqadj_pop(:,okunits); |
| 261 | +expval_trig_pop = expval_trig_pop(:,:,:,okunits); |
| 262 | + |
| 263 | +mexpval_trig_pop = squeeze(mean(expval_trig_pop,4)); |
| 264 | + |
| 265 | +for ievtype = 1:4 |
| 266 | + ax_expval_trig(ievtype) = subplot(4,1,ievtype); |
| 267 | + plot(winSamps, squeeze(mexpval_trig_pop(:,:,ievtype))'); |
| 268 | +end |
| 269 | +linkaxes(ax_expval_trig); |
| 270 | +ylim([-10 40]) |
| 271 | +legend(['all',param.predictorNames],'location','west'); |
| 272 | +screen2png(fullfile(saveServer,[saveSuffix_p animal '_expval_trig' limSuffix '.png'])); |
225 | 273 |
|
226 | 274 |
|
227 | 275 | %% selected units
|
|
0 commit comments