Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

neuralAnalysesDelayShiftAligned.m 56 KB

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