neuralAnalysesOfferShiftAligned.m 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. addpath(genpath('../../../my-tools'));
  2. addpath(genpath('../../../external-tools'));
  3. clearvars -except subjsData poolstack* pooltw*;
  4. %close all; clc;
  5. reload=0; recomp_shLRalgn=1;
  6. recomputelm=1;
  7. Nlag=10; Nspan=200; %Nspan=200;
  8. Nshf=100;
  9. %selflag=1; %LookL during offer1 is most common
  10. %selflag=4; %LookR during offer2 is most common
  11. %selflag=2; %LookR during offer1 is less common
  12. %selflag=3; %LookL during offer2 is less common
  13. %caseflag=1; % perform analysis saccade-aligned forcing stare after saccade
  14. %caseflag=2; % perform analysis saccade-aligned ignoring gaze after saccade
  15. %caseflag=3; % perform analysis for unilateral staring only trials
  16. %caseflag=4; % same as caseflag=1 but forcing offerLL/LR
  17. %caseflag=5; % same as caseflag=2 but forcing offerLL/LR
  18. %caseflag=6; % same as caseflag=3 but forcing offerLL/LR
  19. for selflag=1%[1 4]
  20. for caseflag=2%4:6
  21. close all
  22. clearvars -except subjsData reload recomp_shLRalgn recomputelm Nlag Nspan Nshf selflag caseflag; close all; clc;
  23. stareflag=(caseflag==1 | caseflag==4); %forces stare after saccade
  24. casesstrs={'1_shift_NOoffLR','2_shift_NOstare_NOoffLR','3_NOshift_NOoffLR','4_shift','5_shift_NOstare','6_NOshift'};
  25. disp(['running selflag=' num2str(selflag) '; caseflag=' num2str(caseflag) '; (' casesstrs{caseflag} ')']);
  26. switch selflag
  27. case 1
  28. most_recent_folder=['../../Figures/evLevR_off1LR_' casesstrs{caseflag} '/'];
  29. if ~exist(most_recent_folder,'dir'); mkdir(most_recent_folder); mkdir([most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms']); end
  30. selectedTimes='((ntce_ds(2,1)-40):ntce_ds(2,2))';
  31. %selectedCases{1}='find((cciso1LL) & (ccepx(:,tt)<0))';
  32. %selectedCases{2}='find((cciso1LL) & (ccepx(:,tt)>0))';
  33. %case 2 % DEPRECATED
  34. %most_recent_folder='../../Figures/';
  35. %selectedTimes='(ntce_ds(2,1)-40:ntce_ds(2,2))';
  36. %selectedCases{1}='find((~cciso1LL) & (ccepx(:,tt)<0))';
  37. %selectedCases{2}='find((~cciso1LL) & (ccepx(:,tt)>0))';
  38. %case 3 % DEPRECATED
  39. %most_recent_folder='../../Figures/';
  40. %selectedTimes='(ntce_ds(4,1)-40:ntce_ds(4,2))';
  41. %selectedCases{1}='find((cciso2LL) & (ccepx(:,tt)<0))';
  42. %selectedCases{2}='find((cciso2LL) & (ccepx(:,tt)>0))';
  43. case 4
  44. most_recent_folder=['../../Figures/evLevR_off2LR_' casesstrs{caseflag} '/'];
  45. if ~exist(most_recent_folder,'dir'); mkdir(most_recent_folder); mkdir([most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms']); end
  46. selectedTimes='((ntce_ds(4,1)-40):ntce_ds(4,2))';
  47. %selectedCases{1}='find((~cciso2LL) & (ccepx(:,tt)<0))';
  48. %selectedCases{2}='find((~cciso2LL) & (ccepx(:,tt)>0))';
  49. end
  50. if reload
  51. % if ~exist('subjsData','var')
  52. % subjsData(1).sbdata=getSubjectData(1);
  53. % subjsData(2).sbdata=getSubjectData(2);
  54. % end
  55. if ~exist('poolstackvars','var')
  56. load latestpoolstackvars_14feb22.mat
  57. % or getPoolStackVars.m
  58. end
  59. if ~exist('pooltweyepos','var')
  60. load latestpooltweyepos_14feb22.mat
  61. % or getTimewinsPoolEyePos.m
  62. end
  63. if ~exist('pooltwspksq','var')
  64. load latestpooltwspks_14feb22.mat
  65. % or getTimewinsPoolSpikeSeqs.m
  66. end
  67. twLabels={'preoffer1','offer1','delay1','offer2','delay2','refixate','choice-go','ch-hold'};
  68. nccs=[ 51 59 24 29 18 32 9 26];
  69. ntrs=arrayfun(@(xx) size(poolstackvars(xx).offer1sd,1),1:8);
  70. Nccs=sum(nccs);
  71. Ntrs12=max(ntrs);
  72. Ntps12=arrayfun(@(tw) size(pooltweyepos(tw).posX,3), 1:8);
  73. Ntps12(1)=400;
  74. pooloffer1sd=[]; poolofferLev=[]; poolofferRev=[]; pooloffer1ev=[]; pooloffer2ev=[]; pooloffer1rw=[]; pooloffer2rw=[]; poolofferchR=[];
  75. for sn=1:8
  76. pooloffer1sd=cat(2, pooloffer1sd, repmat(cat(1,poolstackvars(sn).offer1sd,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  77. poolofferLev=cat(2, poolofferLev, repmat(cat(1,poolstackvars(sn).offerLev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  78. poolofferRev=cat(2, poolofferRev, repmat(cat(1,poolstackvars(sn).offerRev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  79. pooloffer1ev=cat(2, pooloffer1ev, repmat(cat(1,poolstackvars(sn).offer1ev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  80. pooloffer2ev=cat(2, pooloffer2ev, repmat(cat(1,poolstackvars(sn).offer2ev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  81. pooloffer1rw=cat(2, pooloffer1rw, repmat(cat(1,poolstackvars(sn).offer1rw,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  82. pooloffer2rw=cat(2, pooloffer2rw, repmat(cat(1,poolstackvars(sn).offer2rw,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  83. poolofferchR=cat(2, poolofferchR, repmat(cat(1,poolstackvars(sn).chooseR,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  84. end
  85. pooleposxmat=cat(3,pooltweyepos(1).posX,pooltweyepos(2).posX,pooltweyepos(3).posX,pooltweyepos(4).posX,...
  86. pooltweyepos(5).posX,pooltweyepos(6).posX,pooltweyepos(7).posX,pooltweyepos(8).posX);
  87. poolspksqmat=cat(3,pooltwspksq(1).spkseqs,pooltwspksq(2).spkseqs,pooltwspksq(3).spkseqs,pooltwspksq(4).spkseqs,...
  88. pooltwspksq(5).spkseqs,pooltwspksq(6).spkseqs,pooltwspksq(7).spkseqs,pooltwspksq(8).spkseqs);
  89. poolspksqmat=cat(3,nan(size(pooltwspksq(1).spkseqs)),nan(size(pooltwspksq(2).spkseqs)),pooltwspksq(3).spkseqs,...
  90. nan(size(pooltwspksq(4).spkseqs)),pooltwspksq(5).spkseqs,nan(size(pooltwspksq(6).spkseqs)),nan(size(pooltwspksq(7).spkseqs)),nan(size(pooltwspksq(8).spkseqs)));
  91. poolcovhist=cat(2,pooltwspksq(1).covhist,pooltwspksq(2).covhist,pooltwspksq(3).covhist,pooltwspksq(4).covhist,...
  92. pooltwspksq(5).covhist,pooltwspksq(6).covhist,pooltwspksq(7).covhist,pooltwspksq(8).covhist);
  93. %clearvars pooltwspksq pooltweyepos
  94. fchg=find(poolcovhist>=.999); fchl=find(poolcovhist<.999);
  95. ntcv=[fchg(diff([fchg sum(Ntps12)])>1)' fchl([diff(fchl) sum(Ntps12)]>1)'];
  96. ntce=[[1; 401; ntcv(1:end-1,2)] [400; ntcv(:,1)]];
  97. vtps=ones(1,sum(Ntps12)); for jj=1:7; vtps(ntcv(jj,1):ntcv(jj,2))=nan; end
  98. %if sparsity==1 it means 1spike/ms that is 1000 spikes/s
  99. %nanmean(vectorise((nansum(poolspksqmat,3))./(nansum(poolspksqmat>=0,3))))*1000
  100. %nanstd(vectorise((nansum(poolspksqmat,3))./(nansum(poolspksqmat>=0,3))))*1000
  101. %% smooth by movmean filtering, downsample to 20ms, 50Hz resolution
  102. Ntps_ds=ceil(sum(Ntps12)/Nlag);
  103. tmax_ds=nanmovmean(1:size(pooleposxmat,3),Nlag,Nlag);
  104. poolspksqmat_ds=nan(Ntrs12,Nccs,length(tmax_ds));
  105. pooleposxmat_ds=nan(Ntrs12,Nccs,length(tmax_ds));
  106. for cc=1:Nccs
  107. poolspksqmat_ds(:,cc,:)=nanmovmean(squeeze(poolspksqmat(:,cc,:))',Nlag,[0 Nspan])';
  108. pooleposxmat_ds(:,cc,:)=nanmovmean(squeeze(pooleposxmat(:,cc,:))',Nlag,Nlag)';
  109. end
  110. clearvars poolspksqmat pooleposxmat
  111. %%
  112. poolcovhist_ds=nanmovmean(poolcovhist,Nlag,Nlag);
  113. %fcgh_ds=find(poolcovhist_ds>=.8); fchl_ds=find(poolcovhist_ds<.8);
  114. fcgh_ds=find(poolcovhist_ds>=.999); fchl_ds=find(poolcovhist_ds<.999);
  115. ntcv_ds=[fcgh_ds(diff([fcgh_ds Ntps_ds])>1)' fchl_ds([diff(fchl_ds) Ntps_ds]>1)'];
  116. vtps_ds=ones(1,Ntps_ds); for jj=1:7; vtps_ds(ntcv_ds(jj,1):ntcv_ds(jj,2))=nan; end
  117. ntce_ds=[[1 ceil(400/Nlag)+1 find(vtps_ds(2:end)+isnan(vtps_ds(1:end-1))==2)+1]' [ceil(400/Nlag) find(vtps_ds(1:end-1)+isnan(vtps_ds(2:end))==2)]'];
  118. Nvtps_ds=sum(vtps_ds==1);
  119. % Apply movmean independently across time windows
  120. % checktps_ds=zeros(1,length(poolcovhist_ds));
  121. % for tw=1:8
  122. % tpvec=zeros(1,length(poolcovhist));
  123. % tpvec(ntce(tw,1):ntce(tw,2))=1;
  124. % tpvec_ds=zeros(1,length(poolcovhist_ds));
  125. % tpvec_ds(ntce_ds(tw,1):ntce_ds(tw,2))=1;
  126. % for cc=1:Nccs
  127. % nnspktemp=nanmovmean(squeeze(poolspksqmat(:,cc,tpvec==1))',Nlag,[0 Nspan])';
  128. % poolspksqmat_ds(:,cc,tpvec_ds==1)=nnspktemp(:,1:sum(tpvec_ds==1));
  129. % nnepxtemp=nanmovmean(squeeze(pooleposxmat(:,cc,tpvec==1))',Nlag,Nlag)';
  130. % pooleposxmat_ds(:,cc,tpvec_ds==1)=nnepxtemp(:,1:sum(tpvec_ds==1));
  131. % end
  132. % checktps_ds(tpvec_ds==1)=checktps_ds(tpvec_ds==1)+tw;
  133. % end
  134. vtmax_ds=rmnans(tmax_ds.*vtps_ds);%find(rmnans(vtps_ds));
  135. rtmax_ds=1:length(vtmax_ds);
  136. rtmes_ds=arrayfun(@(jj) length(ntce_ds(jj,1):ntce_ds(jj,2)), 1:8);
  137. % baseline normalization
  138. %poolspksqmat_ds_bln=poolspksqmat_ds-repmat(nanmean(poolspksqmat_ds(:,:,1:floor(400/Nlag)),3),[1 1 Ntps_ds]);
  139. %clearvars poolspksqmat_ds
  140. % baseline normalization
  141. %poolspksqmat_ds_bln=poolspksqmat_ds./repmat(nanmean(poolspksqmat_ds(:,:,1:floor(400/Nlag)),3)+eps,[1 1 Ntps_ds]);
  142. %poolspksqmat_ds_bln=poolspksqmat_ds-repmat(nanmean(nanmean(poolspksqmat_ds(:,:,1:floor(400/Nlag)),3),1),[Ntrs12 1 Ntps_ds]);
  143. % No baseline normalization
  144. poolspksqmat_ds_bln=poolspksqmat_ds;
  145. else
  146. load pool_all_light.mat
  147. % save time at run-time
  148. end
  149. %%
  150. off1time=ntce_ds(2,2)-(19:-1:0);
  151. %del1time=ntce_ds(3,2)-(19:-1:0);
  152. off2time=ntce_ds(4,2)-(19:-1:0);
  153. %del2time=ntce_ds(5,2)-(19:-1:0);
  154. %fulldel1time=(ntce_ds(3,1)):ntce_ds(3,2);
  155. %fulldel1time=[(ntce_ds(3,1)-46):(ntce_ds(3,1)-7) ntce_ds(3,1):ntce_ds(3,2)];
  156. %fulloff1time=[(ntce_ds(2,1)-46):(ntce_ds(2,1)-7) ntce_ds(2,1):ntce_ds(2,2)];
  157. fulloff1time=[(ntce_ds(2,1)-40):ntce_ds(2,2)];
  158. fulloff1time=fulloff1time(fulloff1time>0); % ensure it is not negative
  159. %fulldel2time=(ntce_ds(5,1)):ntce_ds(6,1)-20-2; % due to spikecount/subsampling setup
  160. %fulldel2time=[(ntce_ds(5,1)-46):(ntce_ds(5,1)-7) ntce_ds(5,1):ntce_ds(6,1)-20-2];
  161. fulloff2time=[(ntce_ds(4,1)-46):(ntce_ds(4,1)-7) ntce_ds(4,1):ntce_ds(4,2)];
  162. %fulloff2time=[(ntce_ds(4,1)-40):ntce_ds(4,2)];
  163. if recomp_shLRalgn
  164. if selflag<=2
  165. %%%%%%%%%%%%%%
  166. pooleposxmat_shRalgn=nan(size(pooleposxmat_ds_bln));
  167. pooleposxmat_shLalgn=nan(size(pooleposxmat_ds_bln));
  168. poolspksqmat_shRalgn=nan(size(poolspksqmat_ds_bln));
  169. poolspksqmat_shLalgn=nan(size(poolspksqmat_ds_bln));
  170. pooleposxmat_shRonly=nan(size(pooleposxmat_ds_bln));
  171. pooleposxmat_shLonly=nan(size(pooleposxmat_ds_bln));
  172. poolspksqmat_shRonly=nan(size(poolspksqmat_ds_bln));
  173. poolspksqmat_shLonly=nan(size(poolspksqmat_ds_bln));
  174. isdelSR=nan(size(poolspksqmat_ds_bln,1:2));
  175. isdelSL=nan(size(poolspksqmat_ds_bln,1:2));
  176. for cc=1:248
  177. % firstL offer1 - thenL delay2
  178. % Detect saccades
  179. ccepx=squeeze(pooleposxmat_ds_bln(:,cc,fulloff1time));
  180. ccspk=squeeze(poolspksqmat_ds_bln(:,cc,fulloff1time));
  181. [nuR,~,~,ishiftsR]=nanmonotonicdrifts_forward_simplified(ccepx(:,40:end),2,0,+1,1,stareflag);
  182. % delay2 shiftR trials have sum(xdriftsR,2)>0
  183. isdelSR(:,cc)=double(~isnan(ishiftsR));
  184. ind_delSR=find(~isnan(ishiftsR));
  185. % saccade R times
  186. %stR=arrayfun(@(xx) find(xdriftsR(xx,:)==1,1,'first'),isSR);
  187. stR=ishiftsR(ind_delSR);
  188. for jj=1:length(ind_delSR)
  189. shRbins=(ishiftsR(ind_delSR(jj)):length(fulloff1time));
  190. pooleposxmat_shRalgn(ind_delSR(jj),cc,fulloff1time)=[ccepx(ind_delSR(jj),shRbins) nan(1,length(fulloff1time)-sum(shRbins<=length(fulloff1time)))];
  191. poolspksqmat_shRalgn(ind_delSR(jj),cc,fulloff1time)=[ccspk(ind_delSR(jj),shRbins) nan(1,length(fulloff1time)-sum(shRbins<=length(fulloff1time)))];
  192. pooleposxmat_shRonly(ind_delSR(jj),cc,fulloff1time(1)-1+shRbins)=ccepx(ind_delSR(jj),shRbins);
  193. poolspksqmat_shRonly(ind_delSR(jj),cc,fulloff1time(1)-1+shRbins)=ccepx(ind_delSR(jj),shRbins);
  194. end
  195. %figure(); plot(1:76,squeeze(pooleposxmat_shRalgn(:,1,fulloff1time)))
  196. %%
  197. [nuL,~,~,ishiftsL]=nanmonotonicdrifts_forward_simplified(ccepx(:,40:end),2,0,-1,1,stareflag);
  198. % delay2 shiftL trials
  199. isdelSL(:,cc)=double(~isnan(ishiftsL));
  200. ind_delSL=find(~isnan(ishiftsL));
  201. % saccade L times
  202. %stL=arrayfun(@(xx) find(xdriftsL(xx,:)==1,1,'first'),isSL);
  203. stL=ishiftsL(ind_delSL);
  204. for jj=1:length(ind_delSL)
  205. shLbins=(ishiftsL(ind_delSL(jj)):length(fulloff1time));
  206. pooleposxmat_shLalgn(ind_delSL(jj),cc,fulloff1time)=[ccepx(ind_delSL(jj),shLbins) nan(1,length(fulloff1time)-sum(shLbins<=length(fulloff1time)))];
  207. poolspksqmat_shLalgn(ind_delSL(jj),cc,fulloff1time)=[ccspk(ind_delSL(jj),shLbins) nan(1,length(fulloff1time)-sum(shLbins<=length(fulloff1time)))];
  208. pooleposxmat_shLonly(ind_delSL(jj),cc,fulloff1time(1)-1+shLbins)=ccepx(ind_delSL(jj),shLbins);
  209. poolspksqmat_shLonly(ind_delSL(jj),cc,fulloff1time(1)-1+shLbins)=ccepx(ind_delSL(jj),shLbins);
  210. end
  211. %figure(); plot(1:76,squeeze(pooleposxmat_shLalgn(:,1,fulloff1time)))
  212. end
  213. %save('pool_del1_shLRalgn.mat','pooleposxmat_shRalgn','poolspksqmat_shRalgn','pooleposxmat_shLalgn','poolspksqmat_shLalgn','-v7.3')
  214. elseif selflag>2
  215. %%%%%%%%%%%%%%%%%%%%%%%
  216. pooleposxmat_shRalgn=nan(size(pooleposxmat_ds_bln));
  217. pooleposxmat_shLalgn=nan(size(pooleposxmat_ds_bln));
  218. poolspksqmat_shRalgn=nan(size(poolspksqmat_ds_bln));
  219. poolspksqmat_shLalgn=nan(size(poolspksqmat_ds_bln));
  220. pooleposxmat_shRonly=nan(size(pooleposxmat_ds_bln));
  221. pooleposxmat_shLonly=nan(size(pooleposxmat_ds_bln));
  222. poolspksqmat_shRonly=nan(size(poolspksqmat_ds_bln));
  223. poolspksqmat_shLonly=nan(size(poolspksqmat_ds_bln));
  224. isdelSR=nan(size(poolspksqmat_ds_bln,1:2));
  225. isdelSL=nan(size(poolspksqmat_ds_bln,1:2));
  226. for cc=1:248
  227. % firstL offer1 - thenL delay2
  228. % Detect saccades
  229. ccepx=squeeze(pooleposxmat_ds_bln(:,cc,fulloff2time));
  230. ccspk=squeeze(poolspksqmat_ds_bln(:,cc,fulloff2time));
  231. [nuR,~,~,ishiftsR]=nanmonotonicdrifts_forward_simplified(ccepx(:,40:end),2,0,+1,1,stareflag);
  232. % delay2 shiftR trials have sum(xdriftsR,2)>0
  233. isdelSR(:,cc)=double(~isnan(ishiftsR));
  234. ind_delSR=find(~isnan(ishiftsR));
  235. % saccade R times
  236. %stR=arrayfun(@(xx) find(xdriftsR(xx,:)==1,1,'first'),isSR);
  237. stR=ishiftsR(ind_delSR);
  238. for jj=1:length(ind_delSR)
  239. shRbins=(ishiftsR(ind_delSR(jj)):length(fulloff2time));
  240. pooleposxmat_shRalgn(ind_delSR(jj),cc,fulloff2time)=[ccepx(ind_delSR(jj),shRbins) nan(1,length(fulloff2time)-sum(shRbins<=length(fulloff2time)))];
  241. poolspksqmat_shRalgn(ind_delSR(jj),cc,fulloff2time)=[ccspk(ind_delSR(jj),shRbins) nan(1,length(fulloff2time)-sum(shRbins<=length(fulloff2time)))];
  242. pooleposxmat_shRonly(ind_delSR(jj),cc,fulloff2time(1)-1+shRbins)=ccepx(ind_delSR(jj),shRbins);
  243. poolspksqmat_shRonly(ind_delSR(jj),cc,fulloff2time(1)-1+shRbins)=ccepx(ind_delSR(jj),shRbins);
  244. end
  245. [nuL,~,~,ishiftsL]=nanmonotonicdrifts_forward_simplified(ccepx(:,40:end),2,0,-1,1,stareflag);
  246. % delay2 shiftL trials
  247. isdelSL(:,cc)=double(~isnan(ishiftsL));
  248. ind_delSL=find(~isnan(ishiftsL));
  249. % saccade L times
  250. %stL=arrayfun(@(xx) find(xdriftsL(xx,:)==1,1,'first'),isSL);
  251. stL=ishiftsL(ind_delSL);
  252. for jj=1:length(ind_delSL)
  253. shLbins=(ishiftsL(ind_delSL(jj)):length(fulloff2time));
  254. pooleposxmat_shLalgn(ind_delSL(jj),cc,fulloff2time)=[ccepx(ind_delSL(jj),shLbins) nan(1,length(fulloff2time)-sum(shLbins<=length(fulloff2time)))];
  255. poolspksqmat_shLalgn(ind_delSL(jj),cc,fulloff2time)=[ccspk(ind_delSL(jj),shLbins) nan(1,length(fulloff2time)-sum(shLbins<=length(fulloff2time)))];
  256. pooleposxmat_shLonly(ind_delSL(jj),cc,fulloff2time(1)-1+shLbins)=ccepx(ind_delSL(jj),shLbins);
  257. poolspksqmat_shLonly(ind_delSL(jj),cc,fulloff2time(1)-1+shLbins)=ccepx(ind_delSL(jj),shLbins);
  258. end
  259. %disp(cc)
  260. end
  261. %save('pool_del2_shLRalgn.mat','pooleposxmat_shRalgn','poolspksqmat_shRalgn','pooleposxmat_shLalgn','poolspksqmat_shLalgn','-v7.3')
  262. end
  263. else
  264. if selflag<=2
  265. load pool_del1_shLRalgn.mat
  266. elseif selflag>2
  267. load pool_del2_shLRalgn.mat
  268. end
  269. end
  270. %% EXTRA CHECKS: plotting percentiles of eye tracks
  271. pooleposxmat_L=nan(Ntrs12,Nccs,Ntps_ds); pooleposxmat_R=nan(Ntrs12,Nccs,Ntps_ds);
  272. if any(caseflag==[1 2 4 5])
  273. pooleposxmat_L=pooleposxmat_shLalgn(:,:,:);
  274. pooleposxmat_R=pooleposxmat_shRalgn(:,:,:);
  275. else
  276. dtime=eval(selectedTimes);
  277. inddelstL=arrayfun(@(xx) all((rmnans(squeeze(pooleposxmat_ds_bln(xx,1,dtime))))<=0), 1:size(pooleposxmat_ds_bln,1));
  278. inddelstR=arrayfun(@(xx) all((rmnans(squeeze(pooleposxmat_ds_bln(xx,1,dtime))))>=0), 1:size(pooleposxmat_ds_bln,1));
  279. pooleposxmat_L(1:sum(inddelstL),:,dtime)=pooleposxmat_ds_bln(inddelstL,:,dtime);
  280. pooleposxmat_R(1:sum(inddelstR),:,dtime)=pooleposxmat_ds_bln(inddelstR,:,dtime);
  281. end
  282. if selflag <=2
  283. hfig=fullfig();
  284. subplot(1,2,1); title('Shifts to Left screen side');
  285. plot(rtmax_ds,(squeeze(pooleposxmat_L(:,1,vtps_ds==1)))./32558); ylim([-1 1]); plothline(0);
  286. xlabel('time after offer1 aligned to gaze shift initiation (ms)'); ylabel('horizontal eye position (normalized)'); box off
  287. subplot(1,2,2); title('Shifts to Right screen side');
  288. plot(rtmax_ds,(squeeze(pooleposxmat_R(:,1,vtps_ds==1)))./32558); ylim([-1 1]); plothline(0);
  289. xlabel('time after offer1 aligned to gaze shift initiation (ms)'); ylabel('horizontal eye position (normalized)'); box off
  290. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.png']);
  291. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.fig']);
  292. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.svg']);
  293. fullfig();
  294. subplot(1,2,1);
  295. plotmsem(fulloff1time,nanmedian(squeeze(pooleposxmat_L(:,1,fulloff1time))),'k');
  296. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),99), fulloff1time),'color',[1 1 1].*.85);
  297. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),01), fulloff1time),'color',[1 1 1].*.85);
  298. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),95), fulloff1time),'color',[1 1 1].*.60);
  299. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),05), fulloff1time),'color',[1 1 1].*.60);
  300. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),90), fulloff1time),'color',[1 1 1].*.45);
  301. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),10), fulloff1time),'color',[1 1 1].*.45);
  302. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),75), fulloff1time),'color',[1 1 1].*.25);
  303. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),25), fulloff1time),'color',[1 1 1].*.25);
  304. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),65), fulloff1time),'color',[0 0 1].*.1);
  305. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),35), fulloff1time),'color',[1 1 1].*.1); %ylim([-1 1]);
  306. plotvline([min(eval(selectedTimes)) max(eval(selectedTimes))]); plothline(0); xlim([min(eval(selectedTimes)) max(eval(selectedTimes))]);
  307. subplot(1,2,2);
  308. plotmsem(fulloff1time,nanmedian(squeeze(pooleposxmat_R(:,1,fulloff1time))),'k');
  309. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),99), fulloff1time),'color',[1 1 1].*.85);
  310. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),01), fulloff1time),'color',[1 1 1].*.85);
  311. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),95), fulloff1time),'color',[1 1 1].*.60);
  312. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),05), fulloff1time),'color',[1 1 1].*.60);
  313. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),90), fulloff1time),'color',[1 1 1].*.45);
  314. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),10), fulloff1time),'color',[1 1 1].*.45);
  315. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),75), fulloff1time),'color',[1 1 1].*.25);
  316. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),25), fulloff1time),'color',[1 1 1].*.25);
  317. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),65), fulloff1time),'color',[0 0 1].*.1);
  318. plot(fulloff1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),35), fulloff1time),'color',[1 1 1].*.1); %ylim([-1 1]);
  319. plotvline([min(eval(selectedTimes)) max(eval(selectedTimes))]); plothline(0); xlim([min(eval(selectedTimes)) max(eval(selectedTimes))]);
  320. else
  321. hfig=fullfig();
  322. subplot(1,2,1); title('Shifts to Left screen side');
  323. plot(rtmax_ds,(squeeze(pooleposxmat_L(:,1,vtps_ds==1)))./32558); ylim([-1 1]); plothline(0);
  324. xlabel('time after delay2 aligned to gaze shift initiation (ms)'); ylabel('horizontal eye position (normalized)'); box off
  325. subplot(1,2,2); title('Shifts to Right screen side');
  326. plot(rtmax_ds,(squeeze(pooleposxmat_R(:,1,vtps_ds==1)))./32558); ylim([-1 1]); plothline(0);
  327. xlabel('time after delay2 aligned to gaze shift initiation (ms)'); ylabel('horizontal eye position (normalized)'); box off
  328. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.png']);
  329. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.fig']);
  330. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.svg']);
  331. %%
  332. fullfig();
  333. subplot(1,2,1);
  334. plotmsem(fulloff2time,nanmedian(squeeze(pooleposxmat_L(:,1,fulloff2time))),'k');
  335. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),99), fulloff2time),'color',[1 1 1].*.85);
  336. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),01), fulloff2time),'color',[1 1 1].*.85);
  337. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),95), fulloff2time),'color',[1 1 1].*.60);
  338. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),05), fulloff2time),'color',[1 1 1].*.60);
  339. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),90), fulloff2time),'color',[1 1 1].*.45);
  340. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),10), fulloff2time),'color',[1 1 1].*.45);
  341. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),75), fulloff2time),'color',[1 1 1].*.25);
  342. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),25), fulloff2time),'color',[1 1 1].*.25);
  343. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),65), fulloff2time),'color',[0 0 1].*.1);
  344. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),35), fulloff2time),'color',[1 1 1].*.1);%ylim([-1 1]);
  345. plotvline([min(eval(selectedTimes)) max(eval(selectedTimes))]); plothline(0); xlim([min(eval(selectedTimes)) max(eval(selectedTimes))]);
  346. subplot(1,2,2);
  347. plotmsem(fulloff2time,nanmedian(squeeze(pooleposxmat_R(:,1,fulloff2time))),'k');
  348. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),99), fulloff2time),'color',[1 1 1].*.85);
  349. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),01), fulloff2time),'color',[1 1 1].*.85);
  350. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),95), fulloff2time),'color',[1 1 1].*.60);
  351. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),05), fulloff2time),'color',[1 1 1].*.60);
  352. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),90), fulloff2time),'color',[1 1 1].*.45);
  353. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),10), fulloff2time),'color',[1 1 1].*.45);
  354. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),75), fulloff2time),'color',[1 1 1].*.25);
  355. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),25), fulloff2time),'color',[1 1 1].*.25);
  356. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),65), fulloff2time),'color',[0 0 1].*.1);
  357. plot(fulloff2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),35), fulloff2time),'color',[1 1 1].*.1);%ylim([-1 1]);
  358. plotvline([min(eval(selectedTimes)) max(eval(selectedTimes))]); plothline(0); xlim([min(eval(selectedTimes)) max(eval(selectedTimes))]);
  359. end
  360. %%
  361. % fullfig();
  362. % subplot(1,4,1);
  363. % spy(vectorisen(~isnan(poolspksqmat_shLalgn(:,cumsum(nccs),:)),1:2));
  364. % subplot(1,4,2);
  365. % spy(vectorisen(~isnan(poolspksqmat_shRalgn(:,cumsum(nccs),:)),1:2));
  366. % subplot(1,4,3);
  367. % spy(vectorisen(~isnan(pooleposxmat_shLalgn(:,cumsum(nccs),:)),1:2));
  368. % subplot(1,4,4);
  369. % spy(vectorisen(~isnan(pooleposxmat_shRalgn(:,cumsum(nccs),:)),1:2));
  370. % title('Aligned to shifts');
  371. %%
  372. hfig=fullfig(); hfig.Position=[0 0 .5 1];
  373. subplot(2,1,1); ylim([0 100]); hold on
  374. plot(rtmax_ds,squeeze(sum(~isnan(pooleposxmat_L(:,cumsum(nccs),vtps_ds==1))))./repmat(ntrs',1,sum(vtps_ds>0))*100); hold on
  375. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  376. subplot(2,1,2); ylim([0 100]); hold on
  377. plot(rtmax_ds,squeeze(sum(~isnan(pooleposxmat_R(:,cumsum(nccs),vtps_ds==1))))./repmat(ntrs',1,sum(vtps_ds>0))*100); hold on
  378. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  379. legend({'subj 1, sn 1','subj 1, sn 2','subj 1, sn 3','subj 1, sn 4','subj 2, sn 1','subj 2, sn 2','subj 2, sn 3','subj 2, sn 4'},'box','off');
  380. switch selflag
  381. case 1
  382. subplot(2,1,1);
  383. title('Look Left Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  384. subplot(2,1,2);
  385. title('Look Left Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  386. case 2
  387. subplot(2,1,1);
  388. title('Look Right Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  389. subplot(2,1,2);
  390. title('Look Right Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  391. case 3
  392. subplot(2,1,1);
  393. title('Look Left Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  394. subplot(2,1,2);
  395. title('Look Left Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  396. case 4
  397. subplot(2,1,1);
  398. title('Look Right Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  399. subplot(2,1,2);
  400. title('Look Right Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  401. end
  402. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del.png']);
  403. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del.fig']);
  404. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del.svg']);
  405. clearvars pooleposxmat_L pooleposxmat_R
  406. %%
  407. if any(caseflag==[1 2 4 5])
  408. hfig=fullfig(); hfig.Position=[0 0 .5 1];
  409. subplot(2,1,1); ylim([0 100]); hold on; gg=gca;
  410. %plot(1:Ntps_ds,squeeze(sum(~isnan(poolspksqmat_shLonly(:,cumsum(nccs),:))))./repmat(ntrs',1,Ntps_ds)*100); hold on
  411. pp=plot(eval(selectedTimes),squeeze(sum(~isnan(poolspksqmat_shLonly(:,cumsum(nccs),eval(selectedTimes)))))./repmat(ntrs',1,length(eval(selectedTimes)))*100); hold on
  412. for jj=1:8
  413. plot(1:Ntps_ds,squeeze(sum(~isnan(poolspksqmat_shLonly(:,sum(nccs(1:jj)),:))))./repmat(ntrs(jj)',1,Ntps_ds)*100,':','color',pp(jj).Color); hold on
  414. end
  415. for jj=1:7; plotvline(ntce_ds(jj,1:2)); text(ntce_ds(jj,1),max(get(gca,'YLim')),twLabels{jj}); end
  416. %xlim([189 438]);%xlim([1 Ntps_ds]);
  417. subplot(2,1,2); ylim([0 100]); hold on
  418. %plot(1:Ntps_ds,squeeze(sum(~isnan(poolspksqmat_shRonly(:,cumsum(nccs),:))))./repmat(ntrs',1,Ntps_ds)*100); hold on
  419. pp=plot(eval(selectedTimes),squeeze(sum(~isnan(poolspksqmat_shRonly(:,cumsum(nccs),eval(selectedTimes)))))./repmat(ntrs',1,length(eval(selectedTimes)))*100); hold on
  420. for jj=1:8
  421. plot(1:Ntps_ds,squeeze(sum(~isnan(poolspksqmat_shRonly(:,sum(nccs(1:jj)),:))))./repmat(ntrs(jj)',1,Ntps_ds)*100,':','color',pp(jj).Color); hold on
  422. end
  423. for jj=1:7; plotvline(ntce_ds(jj,1:2)); tt=text(ntce_ds(jj,1),.85*max(get(gca,'YLim')),twLabels{jj},'Rotation',90); end
  424. legend({'subj 1, sn 1','subj 1, sn 2','subj 1, sn 3','subj 1, sn 4','subj 2, sn 1','subj 2, sn 2','subj 2, sn 3','subj 2, sn 4'},'box','off');
  425. %xlim([189 438]);%xlim([1 Ntps_ds]);
  426. switch selflag
  427. case 1
  428. subplot(2,1,1);
  429. title('Look Left Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  430. subplot(2,1,2);
  431. title('Look Left Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  432. case 2
  433. subplot(2,1,1);
  434. title('Look Right Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  435. subplot(2,1,2);
  436. title('Look Right Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  437. case 3
  438. subplot(2,1,1);
  439. title('Look Left Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  440. subplot(2,1,2);
  441. title('Look Left Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  442. case 4
  443. subplot(2,1,1);
  444. title('Look Right Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  445. subplot(2,1,2);
  446. title('Look Right Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  447. end
  448. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_shifts.png']);
  449. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_shifts.fig']);
  450. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_shifts.svg']);
  451. end
  452. %% Regress EV vs Spiking
  453. if recomputelm
  454. lmELpv=nan(Nccs,Ntps_ds); lmELpv_shf=nan(Nccs,Ntps_ds,Nshf); lmERpv=nan(Nccs,Ntps_ds); lmERpv_shf=nan(Nccs,Ntps_ds,Nshf);
  455. lmELpvLL=nan(Nccs,Ntps_ds); lmELpvLL_shf=nan(Nccs,Ntps_ds,Nshf); lmERpvLL=nan(Nccs,Ntps_ds); lmERpvLL_shf=nan(Nccs,Ntps_ds,Nshf);
  456. lmELpvLR=nan(Nccs,Ntps_ds); lmELpvLR_shf=nan(Nccs,Ntps_ds,Nshf); lmERpvLR=nan(Nccs,Ntps_ds); lmERpvLR_shf=nan(Nccs,Ntps_ds,Nshf);
  457. lmELR2=nan(Nccs,Ntps_ds); lmELR2_shf=nan(Nccs,Ntps_ds,Nshf); lmERR2=nan(Nccs,Ntps_ds); lmERR2_shf=nan(Nccs,Ntps_ds,Nshf);
  458. lmELR2LL=nan(Nccs,Ntps_ds); lmELR2LL_shf=nan(Nccs,Ntps_ds,Nshf); lmERR2LL=nan(Nccs,Ntps_ds); lmERR2LL_shf=nan(Nccs,Ntps_ds,Nshf);
  459. lmELR2LR=nan(Nccs,Ntps_ds); lmELR2LR_shf=nan(Nccs,Ntps_ds,Nshf); lmERR2LR=nan(Nccs,Ntps_ds); lmERR2LR_shf=nan(Nccs,Ntps_ds,Nshf);
  460. lmELb0=nan(Nccs,Ntps_ds); lmELb0_shf=nan(Nccs,Ntps_ds,Nshf); lmERb0=nan(Nccs,Ntps_ds); lmERb0_shf=nan(Nccs,Ntps_ds,Nshf);
  461. lmELb0LL=nan(Nccs,Ntps_ds); lmELb0LL_shf=nan(Nccs,Ntps_ds,Nshf); lmERb0LL=nan(Nccs,Ntps_ds); lmERb0LL_shf=nan(Nccs,Ntps_ds,Nshf);
  462. lmELb0LR=nan(Nccs,Ntps_ds); lmELb0LR_shf=nan(Nccs,Ntps_ds,Nshf); lmERb0LR=nan(Nccs,Ntps_ds); lmERb0LR_shf=nan(Nccs,Ntps_ds,Nshf);
  463. lmELb1=nan(Nccs,Ntps_ds); lmELb1_shf=nan(Nccs,Ntps_ds,Nshf); lmERb1=nan(Nccs,Ntps_ds); lmERb1_shf=nan(Nccs,Ntps_ds,Nshf);
  464. lmELb1LL=nan(Nccs,Ntps_ds); lmELb1LL_shf=nan(Nccs,Ntps_ds,Nshf); lmERb1LL=nan(Nccs,Ntps_ds); lmERb1LL_shf=nan(Nccs,Ntps_ds,Nshf);
  465. lmELb1LR=nan(Nccs,Ntps_ds); lmELb1LR_shf=nan(Nccs,Ntps_ds,Nshf); lmERb1LR=nan(Nccs,Ntps_ds); lmERb1LR_shf=nan(Nccs,Ntps_ds,Nshf);
  466. lmntrsLL=nan(Nccs,Ntps_ds); lmntrsLR=nan(Nccs,Ntps_ds); lmntrsLL_nn=nan(Nccs,Ntps_ds); lmntrsLR_nn=nan(Nccs,Ntps_ds); lmntrsLL_nn_shLalgn=nan(Nccs,Ntps_ds); lmntrsLR_nn_shRalgn=nan(Nccs,Ntps_ds);
  467. for cc=1:Nccs
  468. ccoff1rw=pooloffer1rw(:,cc);
  469. ccoff2rw=pooloffer2rw(:,cc);
  470. ccoff1ev=pooloffer1ev(:,cc);
  471. ccoff2ev=pooloffer2ev(:,cc);
  472. ccspk=squeeze(poolspksqmat_ds_bln(:,cc,:)); % For linear fit
  473. %%%%% ccspk=squeeze(poolspksqmat_ds(:,cc,:)); % For Poisson fit
  474. ccepx=squeeze(pooleposxmat_ds_bln(:,cc,:));
  475. %%% shift aligned
  476. ccspk_shLalgn=squeeze(poolspksqmat_shLalgn(:,cc,:));
  477. ccspk_shRalgn=squeeze(poolspksqmat_shRalgn(:,cc,:));
  478. ccepx_shLalgn=squeeze(pooleposxmat_shLalgn(:,cc,:));
  479. ccepx_shRalgn=squeeze(pooleposxmat_shRalgn(:,cc,:));
  480. ccisdelSL=isdelSL(:,cc);
  481. ccisdelSR=isdelSR(:,cc);
  482. % cciso1LLd2LL=iso1LLd2LL(:,cc);
  483. % cciso1LLd2LR=iso1LLd2LR(:,cc);
  484. %cciso1LLd1LLd2LL=iso1LLd1LLd2LL(:,cc);
  485. %cciso1LLd1LLd2LR=iso1LLd1LLd2LR(:,cc);
  486. % cciso2LRd2LL=iso2LRd2LL(:,cc);
  487. % cciso2LLd2LL=iso2LLd2LL(:,cc);
  488. % cciso2LRd2LR=iso2LRd2LR(:,cc);
  489. % cciso2LLd2LR=iso2LLd2LR(:,cc);
  490. rmallnans=isnan(ccoff1ev);
  491. rmtrials=rmallnans;%(rmallnans | ccoff1rw~=1 | ccoff2rw~=1);
  492. %ccspk(rmallnans,:)=[];
  493. %ccepx(rmallnans,:)=[];
  494. %ccoff1ev(rmallnans)=[];
  495. %ccoff2ev(rmallnans)=[];
  496. ccspk(rmtrials,:)=[];
  497. ccepx(rmtrials,:)=[];
  498. ccoff1ev(rmtrials)=[];
  499. ccoff2ev(rmtrials)=[];
  500. ccoff1rw(rmtrials)=[];
  501. ccoff2rw(rmtrials)=[];
  502. %cciso2LRd2LL(rmtrials)=[];
  503. %cciso2LRd2LR(rmtrials)=[];
  504. %cciso2LLd2LL(rmtrials)=[];
  505. %cciso2LLd2LR(rmtrials)=[];
  506. %cciso1LLd1LLd2LL(rmtrials)=[];
  507. %cciso1LLd1LLd2LR(rmtrials)=[];
  508. ccisdelSL(rmtrials)=[];
  509. ccisdelSR(rmtrials)=[];
  510. ccspk_shLalgn(rmtrials,:)=[];
  511. ccspk_shRalgn(rmtrials,:)=[];
  512. ccepx_shLalgn(rmtrials,:)=[];
  513. ccepx_shRalgn(rmtrials,:)=[];
  514. ccntrs=size(ccspk,1);
  515. % ccspk_shf=nan(Nshf,size(ccspk,1),size(ccspk,2)); %time-shuffle
  516. % for jj=1:Nshf %time-shuffle
  517. % for ttr=1:ccntrs %time-shuffle
  518. % isnn=find(~isnan(ccspk(ttr,:))); %time-shuffle
  519. % ccspk_shf(jj,ttr,isnn)=ccspk(ttr,isnn(randperm(length(isnn)))); %time-shuffle
  520. % %isvtps=find(vtps_ds==1); %time-shuffle
  521. % %ccspk_shf(jj,ttr,isvtps)=ccspk(ttr,isvtps(randperm(length(isvtps)))); %time-shuffle
  522. % end %time-shuffle
  523. % end %time-shuffle
  524. parfor tt=eval(selectedTimes) % delay1
  525. %for tt=eval(selectedTimes)
  526. %parfor tt=(ntce_ds(5,1):ntce_ds(5,2)) % delay2
  527. %for tt=1:Ntps_ds
  528. warning('off','all')
  529. if 1%vtps_ds(tt)==1 % discards low trials times
  530. ctspk=squeeze(ccspk(:,tt));
  531. ctepx=squeeze(ccepx(:,tt));
  532. ctspk_shLalgn=squeeze(ccspk_shLalgn(:,tt));
  533. ctspk_shRalgn=squeeze(ccspk_shRalgn(:,tt));
  534. ctlm1=fitlm(ccoff1ev,ctspk);
  535. ctlm2=fitlm(ccoff2ev,ctspk);
  536. % ctlm1=fitglm(ccoff1ev,ctspk,'linear','Distribution','poisson');
  537. % ctlm2=fitglm(ccoff2ev,ctspk,'linear','Distribution','poisson');
  538. lmELpv(cc,tt)=ctlm1.Coefficients.pValue(2);
  539. lmERpv(cc,tt)=ctlm2.Coefficients.pValue(2);
  540. lmELR2(cc,tt)=ctlm1.Rsquared.Ordinary;
  541. lmERR2(cc,tt)=ctlm2.Rsquared.Ordinary;
  542. lmELb0(cc,tt)=ctlm1.Coefficients.Estimate(1);
  543. lmERb0(cc,tt)=ctlm2.Coefficients.Estimate(1);
  544. lmELb1(cc,tt)=ctlm1.Coefficients.Estimate(2);
  545. lmERb1(cc,tt)=ctlm2.Coefficients.Estimate(2);
  546. cciso1LL=(nanmean(ccepx(:,off1time),2)<0);
  547. %ccisd1LL=(nanmean(ccepx(:,del1time),2)<0);
  548. cciso2LL=(nanmean(ccepx(:,off2time),2)<0);
  549. %ccisd2LL=(nanmean(ccepx(:,del2time),2)<0);
  550. %[nuL,~,~,ishiftsL]=nanmonotonicdrifts_forward_simplified(ccepx(:,fulloff1time),2,0,-1,1,1);
  551. %check1=find(~isnan(ishiftsL));
  552. %check0=find((ccisdelSL));
  553. % ccisd1allLL=(arrayfun(@(xx) all((ccepx(xx,fulloff1time(1)-1+find(~isnan(ccepx(xx,fulloff1time)))))<=0),1:size(ccepx,1)));
  554. % ccisd1allLR=(arrayfun(@(xx) all((ccepx(xx,fulloff1time(1)-1+find(~isnan(ccepx(xx,fulloff1time)))))>=0),1:size(ccepx,1)));
  555. ccisd1allLL=(arrayfun(@(xx) all((ccepx(xx,fulloff1time(41)-1+find(~isnan(ccepx(xx,fulloff1time(41:end))))))<=0),1:size(ccepx,1)));
  556. ccisd1allLR=(arrayfun(@(xx) all((ccepx(xx,fulloff1time(41)-1+find(~isnan(ccepx(xx,fulloff1time(41:end))))))>=0),1:size(ccepx,1)));
  557. %fullfig(); subplot(1,2,1); plot(fulloff1time,ccepx(ccisd1allLL,fulloff1time));
  558. % subplot(1,2,2); plot(fulloff1time,ccepx(ccisd1allLR,fulloff1time));
  559. % ccisd2allLL=(arrayfun(@(xx) all((ccepx(xx,fulloff2time(1)-1+find(~isnan(ccepx(xx,fulloff2time)))))<=0),1:size(ccepx,1)));
  560. % ccisd2allLR=(arrayfun(@(xx) all((ccepx(xx,fulloff2time(1)-1+find(~isnan(ccepx(xx,fulloff2time)))))>=0),1:size(ccepx,1)));
  561. ccisd2allLL=(arrayfun(@(xx) all((ccepx(xx,fulloff2time(41)-1+find(~isnan(ccepx(xx,fulloff2time(41:end))))))<=0),1:size(ccepx,1)));
  562. ccisd2allLR=(arrayfun(@(xx) all((ccepx(xx,fulloff2time(41)-1+find(~isnan(ccepx(xx,fulloff2time(41:end))))))>=0),1:size(ccepx,1)));
  563. %fullfig(); subplot(1,2,1); plot(fulloff2time,ccepx(ccisd2allLL,fulloff2time));
  564. % subplot(1,2,2); plot(fulloff2time,ccepx(ccisd2allLR,fulloff2time));
  565. switch selflag
  566. case 1 % OFFER1 LookL and DELAY1 LookL/R
  567. %isLL=find((cciso1LL) & (ccepx(:,tt)<0));
  568. %isLR=find((cciso1LL) & (ccepx(:,tt)>0));
  569. %isLL=find((cciso1LL) & (ccisdelSL));
  570. %isLR=find((cciso1LL) & (ccisdelSR));
  571. %isLL=find((ccisdelSL));
  572. %isLR=find((ccisdelSR));
  573. switch caseflag
  574. case {1,2}
  575. isLL=find((ccisdelSL));
  576. isLR=find((ccisdelSR));
  577. case 3
  578. isLL=find((ccisd1allLL));
  579. isLR=find((ccisd1allLR));
  580. case {4,5}
  581. isLL=find((cciso1LL) & (ccisdelSL));
  582. isLR=find((cciso1LL) & (ccisdelSR));
  583. case 6
  584. isLL=find((cciso1LL) & (ccisd1allLL)');
  585. isLR=find((cciso1LL) & (ccisd1allLR)');
  586. end
  587. case 2 % OFFER1 LookR and DELAY1 LookL/R
  588. %isLL=find((~cciso1LL) & (ccepx(:,tt)<0));
  589. %isLR=find((~cciso1LL) & (ccepx(:,tt)>0));
  590. isLL=find((~cciso1LL) & (ccisdelSL));
  591. isLR=find((~cciso1LL) & (ccisdelSR));
  592. case 3 % OFFER2 LookL and DELAY2 LookL/R
  593. %isLL=find((cciso2LL) & (ccepx(:,tt)<0));
  594. %isLR=find((cciso2LL) & (ccepx(:,tt)>0));
  595. isLL=find((cciso2LL) & (ccisdelSL));
  596. isLR=find((cciso2LL) & (ccisdelSR));
  597. case 4 % OFFER2 LookR and DELAY2 LookL/R
  598. %isLL=find((~cciso2LL) & (ccepx(:,tt)<0));
  599. %isLR=find((~cciso2LL) & (ccepx(:,tt)>0));
  600. %isLL=find((~cciso2LL) & (ccisdelSL));
  601. %isLR=find((~cciso2LL) & (ccisdelSR));
  602. %isLL=find((ccisdelSL));
  603. %isLR=find((ccisdelSR));
  604. switch caseflag
  605. case {1,2}
  606. isLL=find((ccisdelSL));
  607. isLR=find((ccisdelSR));
  608. case 3
  609. isLL=find((ccisd2allLL));
  610. isLR=find((ccisd2allLR));
  611. case {4,5}
  612. isLL=find((~cciso2LL) & (ccisdelSL));
  613. isLR=find((~cciso2LL) & (ccisdelSR));
  614. case 6
  615. isLL=find((~cciso2LL) & (ccisd2allLL)');
  616. isLR=find((~cciso2LL) & (ccisd2allLR)');
  617. end
  618. %isLL=find((~cciso2LL) & (ccisd2allLL)');
  619. %isLR=find((~cciso2LL) & (ccisd2allLR)');
  620. %isLL=find((ccisd2allLL));
  621. %isLR=find((ccisd2allLR));
  622. end
  623. %Relevant cases:
  624. % Left in offer1 and Right in delay1
  625. % Right in offer2 and Left in delay2
  626. % control cases:
  627. % Right in offer1
  628. % Left in offer2
  629. %isLL=find((~cciso1LL) & (ccepx(:,tt)<0));
  630. %isLL=find((cciso1LL) & (ccepx(:,tt)<0));
  631. %isLL=eval(selectedCases{1});
  632. %isLL=find((~cciso2LL) & (ccepx(:,tt)<0));
  633. %isLL=find((cciso2LL) & (ccepx(:,tt)<0));
  634. %isLL=find(cciso1LL & ccisd1LL & cciso2LL & (ccepx(:,tt)<0));
  635. %isLL=find((~cciso1LL) & (~ccisd1LL) & (~cciso2LL) & (ccepx(:,tt)<0));
  636. niLL=length(isLL);
  637. if (caseflag==3 || caseflag==6)
  638. ctlm1LL=fitlm(ccoff1ev(isLL),ctspk(isLL));
  639. ctlm2LL=fitlm(ccoff2ev(isLL),ctspk(isLL));
  640. else
  641. ctlm1LL=fitlm(ccoff1ev(isLL),ctspk_shLalgn(isLL));
  642. ctlm2LL=fitlm(ccoff2ev(isLL),ctspk_shLalgn(isLL));
  643. end
  644. % ctlm1LL=fitglm(ccoff1ev(isLL),ctspk(isLL),'linear','Distribution','poisson');
  645. % ctlm2LL=fitglm(ccoff2ev(isLL),ctspk(isLL),'linear','Distribution','poisson');
  646. lmELpvLL(cc,tt)=ctlm1LL.Coefficients.pValue(2);
  647. lmERpvLL(cc,tt)=ctlm2LL.Coefficients.pValue(2);
  648. lmELR2LL(cc,tt)=ctlm1LL.Rsquared.Ordinary;
  649. lmERR2LL(cc,tt)=ctlm2LL.Rsquared.Ordinary;
  650. lmELb0LL(cc,tt)=ctlm1LL.Coefficients.Estimate(1);
  651. lmERb0LL(cc,tt)=ctlm2LL.Coefficients.Estimate(1);
  652. lmELb1LL(cc,tt)=ctlm1LL.Coefficients.Estimate(2);
  653. lmERb1LL(cc,tt)=ctlm2LL.Coefficients.Estimate(2);
  654. lmntrsLL(cc,tt)=niLL;
  655. lmntrsLL_nn(cc,tt)=sum(~isnan(ctspk(isLL)));
  656. lmntrsLL_nn_shLalgn(cc,tt)=sum(~isnan(ctspk_shLalgn(isLL)));
  657. %isLR=find((~cciso1LL) & (ccepx(:,tt)>0));
  658. %isLR=find((cciso1LL) & (ccepx(:,tt)>0));
  659. %isLR=eval(selectedCases{2});
  660. %isLR=find((~cciso2LL) & (ccepx(:,tt)>0));
  661. %isLR=find((cciso2LL) & (ccepx(:,tt)>0));
  662. %isLR=find(cciso1LL & ccisd1LL & cciso2LL & (ccepx(:,tt)>0));
  663. %isLR=find((~cciso1LL) & (~ccisd1LL) & (~cciso2LL) & (ccepx(:,tt)>0));
  664. niLR=length(isLR);
  665. if (caseflag==3 || caseflag==6)
  666. ctlm1LR=fitlm(ccoff1ev(isLR),ctspk(isLR));
  667. ctlm2LR=fitlm(ccoff2ev(isLR),ctspk(isLR));
  668. else
  669. ctlm1LR=fitlm(ccoff1ev(isLR),ctspk_shRalgn(isLR));
  670. ctlm2LR=fitlm(ccoff2ev(isLR),ctspk_shRalgn(isLR));
  671. end
  672. % ctlm1LR=fitglm(ccoff1ev(isLR),ctspk(isLR),'linear','Distribution','poisson');
  673. % ctlm2LR=fitglm(ccoff2ev(isLR),ctspk(isLR),'linear','Distribution','poisson');
  674. lmELpvLR(cc,tt)=ctlm1LR.Coefficients.pValue(2);
  675. lmERpvLR(cc,tt)=ctlm2LR.Coefficients.pValue(2);
  676. lmELR2LR(cc,tt)=ctlm1LR.Rsquared.Ordinary;
  677. lmERR2LR(cc,tt)=ctlm2LR.Rsquared.Ordinary;
  678. lmELb0LR(cc,tt)=ctlm1LR.Coefficients.Estimate(1);
  679. lmERb0LR(cc,tt)=ctlm2LR.Coefficients.Estimate(1);
  680. lmELb1LR(cc,tt)=ctlm1LR.Coefficients.Estimate(2);
  681. lmERb1LR(cc,tt)=ctlm2LR.Coefficients.Estimate(2);
  682. lmntrsLR(cc,tt)=niLR;
  683. lmntrsLR_nn(cc,tt)=sum(~isnan(ctspk(isLR)));
  684. lmntrsLR_nn_shRalgn(cc,tt)=sum(~isnan(ctspk_shRalgn(isLR)));
  685. for shf=1:Nshf
  686. i1shf=randperm(ccntrs); %trial-shuffle
  687. i2shf=randperm(ccntrs); %trial-shuffle
  688. isshf=randperm(ccntrs); %trial-shuffle
  689. ctlm1_shf=fitlm(ccoff1ev(i1shf),ctspk(isshf)); %trial-shuffle
  690. ctlm2_shf=fitlm(ccoff2ev(i2shf),ctspk(isshf)); %trial-shuffle
  691. % ctlm1_shf=fitglm(ccoff1ev(i1shf),ctspk(isshf),'linear','Distribution','poisson');
  692. % ctlm2_shf=fitglm(ccoff2ev(i2shf),ctspk(isshf),'linear','Distribution','poisson');
  693. %ctlm1_shf=fitlm(ccoff1ev,squeeze(ccspk_shf(shf,:,tt))); %time-shuffle
  694. %ctlm2_shf=fitlm(ccoff2ev,squeeze(ccspk_shf(shf,:,tt))); %time-shuffle
  695. lmELpv_shf(cc,tt,shf)=ctlm1_shf.Coefficients.pValue(2);
  696. lmERpv_shf(cc,tt,shf)=ctlm2_shf.Coefficients.pValue(2);
  697. lmELR2_shf(cc,tt,shf)=ctlm1_shf.Rsquared.Ordinary;
  698. lmERR2_shf(cc,tt,shf)=ctlm2_shf.Rsquared.Ordinary;
  699. lmELb0_shf(cc,tt,shf)=ctlm1_shf.Coefficients.Estimate(1);
  700. lmERb0_shf(cc,tt,shf)=ctlm2_shf.Coefficients.Estimate(1);
  701. lmELb1_shf(cc,tt,shf)=ctlm1_shf.Coefficients.Estimate(2);
  702. lmERb1_shf(cc,tt,shf)=ctlm2_shf.Coefficients.Estimate(2);
  703. i1LLshf=isLL(randperm(niLL)); %trial-shuffle
  704. i2LLshf=isLL(randperm(niLL)); %trial-shuffle
  705. isLLshf=isLL(randperm(niLL)); %trial-shuffle
  706. if (caseflag==3 || caseflag==6)
  707. ctlm1LL_shf=fitlm(ccoff1ev(i1LLshf),ctspk(isLLshf)); %trial-shuffle
  708. ctlm2LL_shf=fitlm(ccoff2ev(i2LLshf),ctspk(isLLshf)); %trial-shuffle
  709. else
  710. ctlm1LL_shf=fitlm(ccoff1ev(i1LLshf),ctspk_shLalgn(isLLshf)); %trial-shuffle
  711. ctlm2LL_shf=fitlm(ccoff2ev(i2LLshf),ctspk_shLalgn(isLLshf)); %trial-shuffle
  712. end
  713. % ctlm1LL_shf=fitglm(ccoff1ev(i1LLshf),ctspk(isLLshf),'linear','Distribution','poisson');
  714. % ctlm2LL_shf=fitglm(ccoff2ev(i2LLshf),ctspk(isLLshf),'linear','Distribution','poisson');
  715. %ctlm1LL_shf=fitlm(ccoff1ev(isLL),squeeze(ccspk_shf(shf,isLL,tt))); %time-shuffle
  716. %ctlm2LL_shf=fitlm(ccoff2ev(isLL),squeeze(ccspk_shf(shf,isLL,tt))); %time-shuffle
  717. lmELpvLL_shf(cc,tt,shf)=ctlm1LL_shf.Coefficients.pValue(2);
  718. lmERpvLL_shf(cc,tt,shf)=ctlm2LL_shf.Coefficients.pValue(2);
  719. lmELR2LL_shf(cc,tt,shf)=ctlm1LL_shf.Rsquared.Ordinary;
  720. lmERR2LL_shf(cc,tt,shf)=ctlm2LL_shf.Rsquared.Ordinary;
  721. lmELb0LL_shf(cc,tt,shf)=ctlm1LL_shf.Coefficients.Estimate(1);
  722. lmERb0LL_shf(cc,tt,shf)=ctlm2LL_shf.Coefficients.Estimate(1);
  723. lmELb1LL_shf(cc,tt,shf)=ctlm1LL_shf.Coefficients.Estimate(2);
  724. lmERb1LL_shf(cc,tt,shf)=ctlm2LL_shf.Coefficients.Estimate(2);
  725. i1LRshf=isLR(randperm(niLR)); %trial-shuffle
  726. i2LRshf=isLR(randperm(niLR)); %trial-shuffle
  727. isLRshf=isLR(randperm(niLR)); %trial-shuffle
  728. if (caseflag==3 || caseflag==6)
  729. ctlm1LR_shf=fitlm(ccoff1ev(i1LRshf),ctspk(isLRshf)); %trial-shuffle
  730. ctlm2LR_shf=fitlm(ccoff2ev(i2LRshf),ctspk(isLRshf)); %trial-shuffle
  731. else
  732. ctlm1LR_shf=fitlm(ccoff1ev(i1LRshf),ctspk_shRalgn(isLRshf)); %trial-shuffle
  733. ctlm2LR_shf=fitlm(ccoff2ev(i2LRshf),ctspk_shRalgn(isLRshf)); %trial-shuffle
  734. end
  735. % ctlm1LR_shf=fitglm(ccoff1ev(i1LRshf),ctspk(isLRshf),'linear','Distribution','poisson');
  736. % ctlm2LR_shf=fitglm(ccoff2ev(i2LRshf),ctspk(isLRshf),'linear','Distribution','poisson');
  737. %ctlm1LR_shf=fitlm(ccoff1ev(isLR),squeeze(ccspk_shf(shf,isLR,tt))); %time-shuffle
  738. %ctlm2LR_shf=fitlm(ccoff2ev(isLR),squeeze(ccspk_shf(shf,isLR,tt))); %time-shuffle
  739. lmELpvLR_shf(cc,tt,shf)=ctlm1LR_shf.Coefficients.pValue(2);
  740. lmERpvLR_shf(cc,tt,shf)=ctlm2LR_shf.Coefficients.pValue(2);
  741. lmELR2LR_shf(cc,tt,shf)=ctlm1LR_shf.Rsquared.Ordinary;
  742. lmERR2LR_shf(cc,tt,shf)=ctlm2LR_shf.Rsquared.Ordinary;
  743. lmELb0LR_shf(cc,tt,shf)=ctlm1LR_shf.Coefficients.Estimate(1);
  744. lmERb0LR_shf(cc,tt,shf)=ctlm2LR_shf.Coefficients.Estimate(1);
  745. lmELb1LR_shf(cc,tt,shf)=ctlm1LR_shf.Coefficients.Estimate(2);
  746. lmERb1LR_shf(cc,tt,shf)=ctlm2LR_shf.Coefficients.Estimate(2);
  747. end
  748. end
  749. warning('on','all')
  750. end
  751. disp([sprintf('%s',datetime('now','Format','HH:mm')) ' - done: ' num2str(cc) '/' num2str(Nccs) ', ' num2str(cc/Nccs.*100) '%']);
  752. end
  753. save([most_recent_folder 'fitlmstats_span_' num2str(Nspan) 'ms_lag_' num2str(Nlag) 'ms_' date '.mat'],'lmE*','lmntr*');
  754. else
  755. %load(['fitlmstats_span_' num2str(Nspan) 'ms_lag_' num2str(Nlag) 'ms_13-May-2022.mat']);
  756. %load(['fitlmstats_span_' num2str(Nspan) 'ms_lag_' num2str(Nlag) 'ms_26-May-2022-BEST.mat']);
  757. %load('fitlmstats_span_100ms_lag_10ms_21-May-2022.mat');
  758. %load('fitlmstats_span_250ms_lag_10ms_01-Jul-2022.mat');
  759. %load('fitlmstats_span_150ms_lag_10ms_02-Jul-2022.mat');
  760. %load('fitlmstats_span_200ms_lag_10ms_24-Jun-2022_TIMESHUFF.mat');
  761. %load('fitlmstats_span_200ms_lag_10ms_13-Jul-2022.mat');
  762. %load(['fitlmstats_span_' num2str(Nspan) 'ms_lag_' num2str(Nlag) 'ms_06-Sep-2022.mat']);
  763. end
  764. %%
  765. %fullfig();
  766. %subplot(2,1,1);
  767. %plot(rtmax_ds,rmnans((lmntrsLL(:,vtps_ds==1)./(lmntrsLL(:,vtps_ds==1)+lmntrsLR(:,vtps_ds==1)))',1));
  768. %title('Look Left fraction of trials');
  769. %subplot(2,1,2);
  770. %plot(rtmax_ds,rmnans((lmntrsLR(:,vtps_ds==1)./(lmntrsLL(:,vtps_ds==1)+lmntrsLR(:,vtps_ds==1)))',1));
  771. %title('Look Right fraction of trials');
  772. %%
  773. %%
  774. hfig=fullfig(); hfig.Position=[0 0 .5 1];
  775. if any(caseflag==[1 2 4 5])
  776. subplot(2,1,1);
  777. plot(rtmax_ds,(lmntrsLL_nn_shLalgn(cumsum(nccs),vtps_ds==1))./repmat(ntrs',1,nansum(vtps_ds)).*100);
  778. subplot(2,1,2);
  779. plot(rtmax_ds,(lmntrsLR_nn_shRalgn(cumsum(nccs),vtps_ds==1))./repmat(ntrs',1,nansum(vtps_ds)).*100);
  780. else
  781. subplot(2,1,1);
  782. plot(rtmax_ds,(lmntrsLL_nn(cumsum(nccs),vtps_ds==1))./repmat(ntrs',1,nansum(vtps_ds)).*100);
  783. subplot(2,1,2);
  784. plot(rtmax_ds,(lmntrsLR_nn(cumsum(nccs),vtps_ds==1))./repmat(ntrs',1,nansum(vtps_ds)).*100);
  785. end
  786. switch selflag
  787. case 1
  788. subplot(2,1,1);
  789. title('Look Left Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  790. subplot(2,1,2);
  791. title('Look Left Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  792. case 2
  793. subplot(2,1,1);
  794. title('Look Right Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  795. subplot(2,1,2);
  796. title('Look Right Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  797. case 3
  798. subplot(2,1,1);
  799. title('Look Left Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  800. subplot(2,1,2);
  801. title('Look Left Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  802. case 4
  803. subplot(2,1,1);
  804. title('Look Right Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  805. subplot(2,1,2);
  806. title('Look Right Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  807. end
  808. hl=legend(strsplit(sprintf('session %d-',1:8),'-'));
  809. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_selected.png']);
  810. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_selected.fig']);
  811. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_selected.svg']);
  812. %%
  813. %cmp=linspecer(14);
  814. %o1col=cmp(1,:); o2col=cmp(2,:); o1LLcol=cmp(9,:); o1LRcol=cmp(11,:); o2LLcol=cmp(10,:); o2LRcol=cmp(12,:);
  815. %% Plot colors
  816. o1col = [ 55 188 52]/255;
  817. o2col = [ 55 131 200]/255;
  818. o3col = [121 121 121]/255;
  819. o1LLcol=[ 50 148 48]/255;
  820. o2LLcol=[ 55 97 135]/255;
  821. o3LLcol=[ 43 43 43]/255;
  822. o1LRcol=[135 215 133]/255;
  823. o2LRcol=[144 187 226]/255;
  824. o3LRcol=[168 168 168]/255;
  825. o1LLcol=[212 87 28]/255;
  826. o1LRcol=[251 179 144]/255;
  827. o2LLcol=[119 30 152]/255;
  828. o2LRcol=[185 118 210]/255;
  829. %%
  830. lmELpvd=double(lmELpv(:,vtps_ds==1)<0.05);
  831. lmERpvd=double(lmERpv(:,vtps_ds==1)<0.05);
  832. lmELpvdLL=double(lmELpvLL(:,vtps_ds==1)<0.05);
  833. lmERpvdLL=double(lmERpvLL(:,vtps_ds==1)<0.05);
  834. lmELpvdLR=double(lmELpvLR(:,vtps_ds==1)<0.05);
  835. lmERpvdLR=double(lmERpvLR(:,vtps_ds==1)<0.05);
  836. lmELpvd_shf=squeeze(double(lmELpv_shf(:,vtps_ds==1,:)<0.05));
  837. lmERpvd_shf=squeeze(double(lmERpv_shf(:,vtps_ds==1,:)<0.05));
  838. lmELpvdLL_shf=squeeze(double(lmELpvLL_shf(:,vtps_ds==1,:)<0.05));
  839. lmERpvdLL_shf=squeeze(double(lmERpvLL_shf(:,vtps_ds==1,:)<0.05));
  840. lmELpvdLR_shf=squeeze(double(lmELpvLR_shf(:,vtps_ds==1,:)<0.05));
  841. lmERpvdLR_shf=squeeze(double(lmERpvLR_shf(:,vtps_ds==1,:)<0.05));
  842. hfig=fullfig();
  843. subplot(3,1,1);
  844. plotcmapdots([o1col; o2col]); hold on
  845. runlength(nanmean(lmELpvd),squeeze(nanmean(lmELpvd_shf)),1,rtmax_ds,o1col,0.005);
  846. runlength(nanmean(lmERpvd),squeeze(nanmean(lmERpvd_shf)),1,rtmax_ds,o2col,0.002);
  847. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),[0 0.2],'k:'); text(sum(rtmes_ds(1:jj-1)),.21,twLabels{jj}); end
  848. hl=legend({'E(L)','E(R)'}); ylim([0 0.2]); box(hl,'on');
  849. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  850. subplot(3,1,2);
  851. plotcmapdots([o1LLcol; o1LRcol]); hold on
  852. runlength(nanmean(lmELpvdLL),squeeze(nanmean(lmELpvdLL_shf)),1,rtmax_ds,o1LLcol,0.005);
  853. runlength(nanmean(lmELpvdLR),squeeze(nanmean(lmELpvdLR_shf)),1,rtmax_ds,o1LRcol,0.002);
  854. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),[0 0.2],'k:'); text(sum(rtmes_ds(1:jj-1)),.21,twLabels{jj}); end
  855. hl=legend({'E(L), LookL','E(L), LookR'}); ylim([0 0.2]); box(hl,'on');
  856. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  857. subplot(3,1,3);
  858. plotcmapdots([o2LLcol; o2LRcol]);
  859. runlength(nanmean(lmERpvdLL),squeeze(nanmean(lmERpvdLL_shf)),1,rtmax_ds,o2LLcol,0.005);
  860. runlength(nanmean(lmERpvdLR),squeeze(nanmean(lmERpvdLR_shf)),1,rtmax_ds,o2LRcol,0.002);
  861. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),[0 0.2],'k:'); text(sum(rtmes_ds(1:jj-1)),.21,twLabels{jj}); end
  862. hl=legend({'E(R), LookL','E(R), LookR'}); ylim([0 0.2]); box(hl,'on');
  863. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  864. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv.png']);
  865. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv.fig']);
  866. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv.svg']);
  867. %%
  868. lmELpvd=double(lmELpv(:,:)<0.05);
  869. lmERpvd=double(lmERpv(:,:)<0.05);
  870. lmELpvdLL=double(lmELpvLL(:,:)<0.05);
  871. lmERpvdLL=double(lmERpvLL(:,:)<0.05);
  872. lmELpvdLR=double(lmELpvLR(:,:)<0.05);
  873. lmERpvdLR=double(lmERpvLR(:,:)<0.05);
  874. lmELpvd_shf=squeeze(double(lmELpv_shf(:,:,:)<0.05));
  875. lmERpvd_shf=squeeze(double(lmERpv_shf(:,:,:)<0.05));
  876. lmELpvdLL_shf=squeeze(double(lmELpvLL_shf(:,:,:)<0.05));
  877. lmERpvdLL_shf=squeeze(double(lmERpvLL_shf(:,:,:)<0.05));
  878. lmELpvdLR_shf=squeeze(double(lmELpvLR_shf(:,:,:)<0.05));
  879. lmERpvdLR_shf=squeeze(double(lmERpvLR_shf(:,:,:)<0.05));
  880. hfig=fullfig();
  881. subplot(3,1,1);
  882. plotcmapdots([o1col; o2col]);
  883. runlength(nanmean(lmELpvd),squeeze(nanmean(lmELpvd_shf)),1,1:Ntps_ds,o1col,0.005);
  884. runlength(nanmean(lmERpvd),squeeze(nanmean(lmERpvd_shf)),1,1:Ntps_ds,o2col,0.002);
  885. ylim([0 0.2]); for jj=1:7; plotvline(ntce_ds(jj,1:2)); text(ntce_ds(jj,1),max(get(gca,'YLim')),twLabels{jj}); end
  886. hl=legend({'E(L)','E(R)'}); box(hl,'on'); box off;
  887. if selflag<=2; xlim(fulloff1time([1 end])); else; xlim(fulloff2time([1 end])); end
  888. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  889. subplot(3,1,2);
  890. plotcmapdots([o1LLcol; o1LRcol]);
  891. runlength(nanmean(lmELpvdLL),squeeze(nanmean(lmELpvdLL_shf)),1,1:Ntps_ds,o1LLcol,0.005);
  892. runlength(nanmean(lmELpvdLR),squeeze(nanmean(lmELpvdLR_shf)),1,1:Ntps_ds,o1LRcol,0.002);
  893. ylim([0 0.2]); for jj=1:7; plotvline(ntce_ds(jj,1:2)); text(ntce_ds(jj,1),max(get(gca,'YLim')),twLabels{jj}); end
  894. hl=legend({'E(L), LookL','E(L), LookR'}); box(hl,'on'); box off;
  895. if selflag<=2; xlim(fulloff1time([1 end])); else; xlim(fulloff2time([1 end])); end
  896. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  897. subplot(3,1,3);
  898. plotcmapdots([o2LLcol; o2LRcol]);
  899. runlength(nanmean(lmERpvdLL),squeeze(nanmean(lmERpvdLL_shf)),1,1:Ntps_ds,o2LLcol,0.005);
  900. runlength(nanmean(lmERpvdLR),squeeze(nanmean(lmERpvdLR_shf)),1,1:Ntps_ds,o2LRcol,0.002);
  901. ylim([0 0.2]); for jj=1:7; plotvline(ntce_ds(jj,1:2)); text(ntce_ds(jj,1),max(get(gca,'YLim')),twLabels{jj}); end
  902. hl=legend({'E(R), LookL','E(R), LookR'}); box(hl,'on'); box off;
  903. if selflag<=2; xlim(fulloff1time([1 end])); else; xlim(fulloff2time([1 end])); end
  904. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  905. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv_deltime.png']);
  906. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv_deltime.fig']);
  907. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv_deltime.svg']);
  908. end
  909. end