process_Spectral_Power_V1V4_AllTimeWins.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. addpath(genpath('./support_routines'));
  2. addpath(genpath('./support_tools'));
  3. clear all; close all; clc;
  4. sSubjectName='monkey 2';
  5. sVisualArea='V1';
  6. subjectInfos=getSubjectInfos(sSubjectName);
  7. subjectData=getSubjectData(sSubjectName,sVisualArea,'ALL','LFPs','ALL');
  8. SAMPLING_FREQ=1017.38;
  9. NUM_TIME_SAMPLES=512;
  10. NUM_FREQ_SAMPLES=NUM_TIME_SAMPLES/2+1;
  11. timeAxis=linspace(0,NUM_TIME_SAMPLES/SAMPLING_FREQ,NUM_TIME_SAMPLES);
  12. freqAxis=linspace(0,SAMPLING_FREQ/2,NUM_FREQ_SAMPLES);
  13. lamLayerTag={'Supra','Granr','Infra'};
  14. gratCondTag={'RF','OUT1','OUT2'};
  15. timeWinTag={'PostStim','Stationary','PostCue','PreFirstDim','PreSecondDim','PreThirdDim'};
  16. plotPmtsPenAvg=0;
  17. plotPmtsPenAvgOutMean=1;
  18. plotPmtsPenAvgOutMeanPreFirstDimOverlayed=1;
  19. plotPmtsPenAvgOutMeanPoolLayersPreFirstDimOverlayed=1;
  20. for reportPmtMinusMean=1%0:1
  21. % reportPmtMinusMean allows to choose how to apply baseline normalization
  22. % reportPmtMinusMean = 0 reports (Pmt) ./ (MeanPmtbaseline)
  23. % reportPmtMinusMean = 1 reports (Pmt - MeanPmtbaseline)./(stdPmtbaseline)
  24. %% Chronux settings (support_tools) - http://chronux.org/
  25. % "Observed Brain Dynamics", P. Mitra and H. Bokil, Oxford University Press, New York, 2008.
  26. paramsMT=[];
  27. paramsMT.Fs=SAMPLING_FREQ;
  28. paramsMT.tapers = [2 3];
  29. paramsMt.pad = 0;
  30. pr=1;
  31. for pp=1:length(subjectData.penIDs) % LOOP OVER PENS
  32. if ~isempty(subjectData.LfpStruct(pp).Sorted)
  33. for ll=1:3 % LOOP OVER LAMINAR LAYERS
  34. for cnd=1:3 % LOOP OVER GRAT CONDITIONS
  35. currLFPsPreStim=subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreStimDataBi(:,:,end-NUM_TIME_SAMPLES+1:end);
  36. currLFPsPostStim=subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PostStimDataBi(:,:,1:NUM_TIME_SAMPLES);
  37. currLFPsStationary=subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).StationaryDataBi(:,:,1:NUM_TIME_SAMPLES);
  38. currLFPsPostCue=subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PostCueDataBi(:,:,1:NUM_TIME_SAMPLES);
  39. currLFPsPreFirstDim=subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreFirstDimDataBi(:,:,end-NUM_TIME_SAMPLES+1:end);
  40. % SELECT GRATCONDS 2, 3, 4, 5, 9, 11, 15, 17, 20, 21, 22, 23, 27, 29, 33, 35
  41. % This stage is necessary to ensure that time windows before dimmings do not include
  42. % trials with changes in power due to dimming of stimuli / contrast changes at RF location
  43. if ~isempty(subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreSecondDimDataBi)
  44. currNumTrials2=length(subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).gratCondSecondDim);
  45. currCorrectSecondDimTrials=find(arrayfun(@(jj) any([2 3 4 5 20 21 22 23 9 11 15 17 27 29 33 35]==subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).gratCondSecondDim(jj)), 1:currNumTrials2));
  46. currLFPsPreSecondDim=subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreSecondDimDataBi(:,currCorrectSecondDimTrials,end-NUM_TIME_SAMPLES+1:end);
  47. else
  48. currLFPsPreSecondDim=[];
  49. end
  50. % Note by the time of THIRD DIM the contrast is fixed in the RF iff the trial is ATTEND RF
  51. if ~isempty(subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreThirdDimDataBi)
  52. currNumTrials3=length(subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).gratCondThirdDim);
  53. currCorrectThirdDimTrials=find(arrayfun(@(jj) any([2 3 4 5 20 21 22 23 9 11 15 17 27 29 33 35]==subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).gratCondThirdDim(jj)), 1:currNumTrials3));
  54. currLFPsPreThirdDim=subjectData.LfpStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreThirdDimDataBi(:,currCorrectThirdDimTrials,end-NUM_TIME_SAMPLES+1:end);
  55. else
  56. currLFPsPreThirdDim=[];
  57. end
  58. currNumChs=size(currLFPsPreStim,1); currNumTrials=size(currLFPsPreFirstDim,2);
  59. currNumTrials2=size(currLFPsPreSecondDim,2); currNumTrials3=size(currLFPsPreThirdDim,2);
  60. currPmtPrSt=nan(currNumChs,currNumTrials,NUM_FREQ_SAMPLES);
  61. currPmtPsSt=nan(currNumChs,currNumTrials,NUM_FREQ_SAMPLES);
  62. currPmtStat=nan(currNumChs,currNumTrials,NUM_FREQ_SAMPLES);
  63. currPmtPsCu=nan(currNumChs,currNumTrials,NUM_FREQ_SAMPLES);
  64. currPmtPFDm=nan(currNumChs,currNumTrials,NUM_FREQ_SAMPLES);
  65. currPmtPostStimZSc=nan(currNumChs,currNumTrials,NUM_FREQ_SAMPLES);
  66. currPmtStationaryZSc=nan(currNumChs,currNumTrials,NUM_FREQ_SAMPLES);
  67. currPmtPostCueZSc=nan(currNumChs,currNumTrials,NUM_FREQ_SAMPLES);
  68. currPmtPreFirstDimZSc=nan(currNumChs,currNumTrials,NUM_FREQ_SAMPLES);
  69. currPmtPreSecondDimZSc=nan(currNumChs,currNumTrials2,NUM_FREQ_SAMPLES);
  70. currPmtPreThirdDimZSc=nan(currNumChs,currNumTrials3,NUM_FREQ_SAMPLES);
  71. for ch=1:currNumChs
  72. % FULL BAND CASE: Pmt of LFPs ZScored in frequency domain
  73. currPmtPreStim=mtspectrumc(squeeze(currLFPsPreStim(ch,:,:))',paramsMT)';
  74. currPmtPostStim=mtspectrumc(squeeze(currLFPsPostStim(ch,:,:))',paramsMT)';
  75. currPmtStationary=mtspectrumc(squeeze(currLFPsStationary(ch,:,:))',paramsMT)';
  76. currPmtPostCue=mtspectrumc(squeeze(currLFPsPostCue(ch,:,:))',paramsMT)';
  77. currPmtPreFirstDim=mtspectrumc(squeeze(currLFPsPreFirstDim(ch,:,:))',paramsMT)';
  78. currPmtPreSecondDim=mtspectrumc(squeeze(currLFPsPreSecondDim(ch,:,:))',paramsMT)';
  79. currPmtPreThirdDim=mtspectrumc(squeeze(currLFPsPreThirdDim(ch,:,:))',paramsMT)';
  80. currPmtPreStimRepMean=repmat(nanmean(currPmtPreStim,1),currNumTrials,1);
  81. currPmtPreStimRepStd=repmat(nanstd(currPmtPreStim,[],1),currNumTrials,1);
  82. if reportPmtMinusMean
  83. currPmtPostStimZSc(ch,:,:)=(currPmtPostStim-currPmtPreStimRepMean)./(currPmtPreStimRepStd+eps);
  84. currPmtStationaryZSc(ch,:,:)=(currPmtStationary-currPmtPreStimRepMean)./(currPmtPreStimRepStd+eps);
  85. currPmtPostCueZSc(ch,:,:)=(currPmtPostCue-currPmtPreStimRepMean)./(currPmtPreStimRepStd+eps);
  86. currPmtPreFirstDimZSc(ch,:,:)=(currPmtPreFirstDim-currPmtPreStimRepMean)./(currPmtPreStimRepStd+eps);
  87. currPmtPreSecondDimZSc(ch,:,:)=(currPmtPreSecondDim-currPmtPreStimRepMean(1:currNumTrials2,:))./(currPmtPreStimRepStd(1:currNumTrials2,:)+eps);
  88. currPmtPreThirdDimZSc(ch,:,:)=(currPmtPreThirdDim-currPmtPreStimRepMean(1:currNumTrials3,:))./(currPmtPreStimRepStd(1:currNumTrials3,:)+eps);
  89. else
  90. currPmtPostStimZSc(ch,:,:)=(currPmtPostStim)./(currPmtPreStimRepMean+eps);
  91. currPmtStationaryZSc(ch,:,:)=(currPmtStationary)./(currPmtPreStimRepMean+eps);
  92. currPmtPostCueZSc(ch,:,:)=(currPmtPostCue)./(currPmtPreStimRepMean+eps);
  93. currPmtPreFirstDimZSc(ch,:,:)=(currPmtPreFirstDim)./(currPmtPreStimRepMean+eps);
  94. currPmtPreSecondDimZSc(ch,:,:)=(currPmtPreSecondDim(1:currNumTrials2,:))./(currPmtPreStimRepMean(1:currNumTrials2,:)+eps);
  95. currPmtPreThirdDimZSc(ch,:,:)=(currPmtPreThirdDim(1:currNumTrials3,:))./(currPmtPreStimRepMean(1:currNumTrials3,:)+eps);
  96. end
  97. currPmtPrSt(ch,:,:)=currPmtPreStim;
  98. currPmtPsSt(ch,:,:)=currPmtPostStim;
  99. currPmtStat(ch,:,:)=currPmtStationary;
  100. currPmtPsCu(ch,:,:)=currPmtPostCue;
  101. currPmtPFDm(ch,:,:)=currPmtPreFirstDim;
  102. end
  103. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PostStimZSc=permute(nanmean(currPmtPostStimZSc,2),[1 3 2]);
  104. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).StationaryZSc=permute(nanmean(currPmtStationaryZSc,2),[1 3 2]);
  105. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PostCueZSc=permute(nanmean(currPmtPostCueZSc,2),[1 3 2]);
  106. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreFirstDimZSc=permute(nanmean(currPmtPreFirstDimZSc,2),[1 3 2]);
  107. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreSecondDimZSc=permute(nanmean(currPmtPreSecondDimZSc,2),[1 3 2]);
  108. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreThirdDimZSc=permute(nanmean(currPmtPreThirdDimZSc,2),[1 3 2]);
  109. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PrStim=permute(nanmean(currPmtPrSt,2),[1 3 2]);
  110. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PsStim=permute(nanmean(currPmtPsSt,2),[1 3 2]);
  111. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).Statry=permute(nanmean(currPmtStat,2),[1 3 2]);
  112. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PstCue=permute(nanmean(currPmtPsCu,2),[1 3 2]);
  113. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PrFDim=permute(nanmean(currPmtPFDm,2),[1 3 2]);
  114. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).(subjectData.penInfos(pp).grcColorOrder).PostStimZSc=permute(nanmean(currPmtPostStimZSc,2),[1 3 2]);
  115. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).(subjectData.penInfos(pp).grcColorOrder).StationaryZSc=permute(nanmean(currPmtStationaryZSc,2),[1 3 2]);
  116. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).(subjectData.penInfos(pp).grcColorOrder).PostCueZSc=permute(nanmean(currPmtPostCueZSc,2),[1 3 2]);
  117. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).(subjectData.penInfos(pp).grcColorOrder).PreFirstDimZSc=permute(nanmean(currPmtPreFirstDimZSc,2),[1 3 2]);
  118. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).(subjectData.penInfos(pp).grcColorOrder).PreSecondDimZSc=permute(nanmean(currPmtPreSecondDimZSc,2),[1 3 2]);
  119. PmtStruct(pr).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).(subjectData.penInfos(pp).grcColorOrder).PreThirdDimZSc=permute(nanmean(currPmtPreThirdDimZSc,2),[1 3 2]);
  120. clear -regexp ^curr % saves memory at runtime
  121. end
  122. end
  123. pr=pr+1;
  124. end
  125. end
  126. %% POOL CHANNELS ACROSS PENs
  127. for ll=1:3
  128. for cnd=1:3
  129. currPmtPostStimZSc=[];
  130. currPmtStationaryZSc=[];
  131. currPmtPostCueZSc=[];
  132. currPmtPreFirstDimZSc=[];
  133. currPmtPreSecondDimZSc=[];
  134. currPmtPreThirdDimZSc=[];
  135. currPmtPreStim=[];
  136. currPmtPostStim=[];
  137. currPmtStationary=[];
  138. currPmtPostCue=[];
  139. currPmtPreFirstDim=[];
  140. for pp=1:length(PmtStruct)
  141. currPmtPreStim= [currPmtPreStim; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PrStim];
  142. currPmtPostStim= [currPmtPostStim; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PsStim];
  143. currPmtStationary= [currPmtStationary; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).Statry];
  144. currPmtPostCue= [currPmtPostCue; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PstCue];
  145. currPmtPreFirstDim= [currPmtPreFirstDim; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PrFDim];
  146. currPmtPostStimZSc= [currPmtPostStimZSc; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PostStimZSc];
  147. currPmtStationaryZSc= [currPmtStationaryZSc; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).StationaryZSc];
  148. currPmtPostCueZSc= [currPmtPostCueZSc; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PostCueZSc];
  149. currPmtPreFirstDimZSc= [currPmtPreFirstDimZSc; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreFirstDimZSc];
  150. currPmtPreSecondDimZSc= [currPmtPreSecondDimZSc; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreSecondDimZSc];
  151. currPmtPreThirdDimZSc= [currPmtPreThirdDimZSc; PmtStruct(pp).Sorted.Full.(lamLayerTag{ll}).(gratCondTag{cnd}).PreThirdDimZSc];
  152. end
  153. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).PostStimZSc=currPmtPostStimZSc;
  154. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).StationaryZSc=currPmtStationaryZSc;
  155. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).PostCueZSc=currPmtPostCueZSc;
  156. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).PreFirstDimZSc=currPmtPreFirstDimZSc;
  157. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).PreSecondDimZSc=currPmtPreSecondDimZSc;
  158. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).PreThirdDimZSc=currPmtPreThirdDimZSc;
  159. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).PrStim=currPmtPreStim;
  160. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).PsStim=currPmtPostStim;
  161. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).Statry=currPmtStationary;
  162. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).PstCue=currPmtPostCue;
  163. PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).PrFDim=currPmtPreFirstDim;
  164. clear -regexp ^curr % saves memory at runtime
  165. end
  166. end
  167. %% PLOT MEAN ACROSS PENS
  168. if plotPmtsPenAvg
  169. figure('units','normalized','outerposition',[0 0 1 1]);
  170. for tt=1:6
  171. for ll=1:3
  172. currSpectPowRF=PoolPmtStruct.(lamLayerTag{ll}).RF.([timeWinTag{tt} 'ZSc']);
  173. currSpectPowOUT=nanmean(cat(4,PoolPmtStruct.(lamLayerTag{ll}).OUT1.([timeWinTag{tt} 'ZSc']),...
  174. PoolPmtStruct.(lamLayerTag{ll}).OUT2.([timeWinTag{tt} 'ZSc'])),4);
  175. numPooledChs=size(currSpectPowRF,1);
  176. subplot(3,6,(ll-1)*6+tt);
  177. plotcmapdots([eye(3); .5 .5 .5]);
  178. if reportPmtMinusMean
  179. plot(freqAxis,zeros(1,length(freqAxis)),'k');
  180. end
  181. for cnd=1:(1+2*double(tt<6)) % Pre3rdDim is just RF
  182. plotmsem(freqAxis,PoolPmtStruct.(lamLayerTag{ll}).(gratCondTag{cnd}).([timeWinTag{tt} 'ZSc']),double([1 2 3]==cnd)); hold on;
  183. end
  184. title([timeWinTag{tt} ' - ' lamLayerTag{ll} ' Layer']);
  185. xlim([0 100]);
  186. if strcmp(sVisualArea,'V1')
  187. if reportPmtMinusMean; ylim([-1 8]); else; ylim([0 8]); end
  188. else
  189. if reportPmtMinusMean; ylim([-1 2.5]); else; ylim([0 2.5]); end
  190. end
  191. if ll==3; xlabel('Frequency [Hz]'); end
  192. if tt==1; ylabel('Baseline-Normalized Power');
  193. if strcmp(sVisualArea,'V1')
  194. text(3,7.5,['n=' num2str(numPooledChs) ';']);
  195. else
  196. text(3,2.3,['n=' num2str(numPooledChs) ';']);
  197. end
  198. end
  199. if tt<6
  200. pValuesVec=nan(1,sum(freqAxis<100));
  201. for ff=1:sum(freqAxis<100)
  202. pValuesVec(ff)=signrank(currSpectPowRF(:,ff),currSpectPowOUT(:,ff));
  203. end
  204. [~,~,~,pValuesVecFDR]=fdr_bh(pValuesVec);
  205. pValuesBar05FDR=nan(1,sum(freqAxis<100));
  206. if reportPmtMinusMean
  207. pValuesBar05FDR(pValuesVecFDR<=.05)=-1;
  208. else
  209. pValuesBar05FDR(pValuesVecFDR<=.05)=0;
  210. end
  211. plot(freqAxis(freqAxis<100),pValuesBar05FDR,'color',[.5 .5 .5],'linewidth',2.5);
  212. end
  213. set(gca,'XTick',0:20:100);%set(gca,'XTickLabel',{'0','10','20','30','40','50','60','70','80','90','100'});
  214. end
  215. end
  216. legend('RF','OUT1','OUT2','p\leq 0.05');
  217. supertitle([sSubjectName ' ' sVisualArea ' - Avg across PENs - LFPs Spectral Power ' spectWinTag{bb} ' Band']);
  218. end
  219. %% PLOT MEAN ACROSS PENS OUT=OUT1/2+OUT2/2
  220. if plotPmtsPenAvgOutMean
  221. figure('units','normalized','outerposition',[0 0 1 1]);
  222. for tt=1:6
  223. for ll=1:3
  224. currSpectPowRF=PoolPmtStruct.(lamLayerTag{ll}).RF.([timeWinTag{tt} 'ZSc']);
  225. currSpectPowOUT=nanmean(cat(4,PoolPmtStruct.(lamLayerTag{ll}).OUT1.([timeWinTag{tt} 'ZSc']),...
  226. PoolPmtStruct.(lamLayerTag{ll}).OUT2.([timeWinTag{tt} 'ZSc'])),4);
  227. numPooledChs=size(currSpectPowRF,1);
  228. subplot(3,6,(ll-1)*6+tt);
  229. plotcmapdots([1 0 0; 0 0 1; .5 .5 .5]);
  230. if reportPmtMinusMean
  231. plot(freqAxis,zeros(1,length(freqAxis)),'k');
  232. end
  233. plotmsem(freqAxis,currSpectPowRF,'r');
  234. if tt<6
  235. plotmsem(freqAxis,currSpectPowOUT,'b');
  236. end
  237. title([timeWinTag{tt} ' - ' lamLayerTag{ll} ' Layer']);
  238. xlim([0 100]);
  239. if strcmp(sVisualArea,'V1')
  240. if reportPmtMinusMean; ylim([-1 8]); else; ylim([0 8]); end
  241. else
  242. if reportPmtMinusMean; ylim([-1 2.5]); else; ylim([0 2.5]); end
  243. end
  244. if ll==3; xlabel('Frequency [Hz]'); end
  245. if tt==1; ylabel('Baseline-Normalized Power');
  246. if strcmp(sVisualArea,'V1')
  247. text(3,7.5,['n=' num2str(numPooledChs) ';']);
  248. else
  249. text(3,2.3,['n=' num2str(numPooledChs) ';']);
  250. end
  251. end
  252. if tt<6
  253. pValuesVec=nan(1,sum(freqAxis<100));
  254. for ff=1:sum(freqAxis<100)
  255. pValuesVec(ff)=signrank(currSpectPowRF(:,ff),currSpectPowOUT(:,ff));
  256. end
  257. [~,~,~,pValuesVecFDR]=fdr_bh(pValuesVec);
  258. pValuesBar05FDR=nan(1,sum(freqAxis<100));
  259. if reportPmtMinusMean
  260. pValuesBar05FDR(pValuesVecFDR<=.05)=-1;
  261. else
  262. pValuesBar05FDR(pValuesVecFDR<=.05)=0;
  263. end
  264. plot(freqAxis(freqAxis<100),pValuesBar05FDR,'color',[0 0 0],'linewidth',2.5);
  265. end
  266. set(gca,'XTick',0:20:100);
  267. end
  268. end
  269. legend('RF','OUT','p\leq 0.05');
  270. supertitle([sSubjectName ' ' sVisualArea ' - Avg across PENs - LFPs Spectral Power']);
  271. end
  272. %% PLOT MEAN ACROSS PENS OVERLAY FIRST DIM OUT=OUT1/2+OUT2/2, PREFIRSTDIM OVERLAYED (DASHED)
  273. if plotPmtsPenAvgOutMeanPreFirstDimOverlayed
  274. figure('units','normalized','outerposition',[0 0 1 1]);
  275. for tt=1:3
  276. for ll=1:3
  277. currSpectPowRF=PoolPmtStruct.(lamLayerTag{ll}).RF.([timeWinTag{tt} 'ZSc']);
  278. currSpectPowOUT=nanmean(cat(4,PoolPmtStruct.(lamLayerTag{ll}).OUT1.([timeWinTag{tt} 'ZSc']),...
  279. PoolPmtStruct.(lamLayerTag{ll}).OUT2.([timeWinTag{tt} 'ZSc'])),4);
  280. numPooledChs=size(currSpectPowRF,1);
  281. subplot(3,3,(ll-1)*3+tt);
  282. plotcmapdots([1 0 0; 0 0 1; .5 .5 .5]);
  283. if reportPmtMinusMean; plot(freqAxis,zeros(1,length(freqAxis)),'k'); end
  284. plotmsem(freqAxis,currSpectPowRF,'r');
  285. if tt<6; plotmsem(freqAxis,currSpectPowOUT,'b'); end
  286. currSpectPowPFDRF=PoolPmtStruct.(lamLayerTag{ll}).RF.PreFirstDimZSc;
  287. currSpectPowPFDOUT=nanmean(cat(4,PoolPmtStruct.(lamLayerTag{ll}).OUT1.PreFirstDimZSc,...
  288. PoolPmtStruct.(lamLayerTag{ll}).OUT2.PreFirstDimZSc),4);
  289. plotmsem(freqAxis,currSpectPowPFDRF,'r:');
  290. plotmsem(freqAxis,currSpectPowPFDOUT,'b:');
  291. title([timeWinTag{tt} ' - ' lamLayerTag{ll} ' Layer']);
  292. xlim([0 100]);
  293. if strcmp(sVisualArea,'V1')
  294. if reportPmtMinusMean
  295. if strcmpi(sSubjectName,'Wyman'); ylim([-1 8]); else; ylim([-1 4]); end
  296. else
  297. ylim([0 8]);
  298. end
  299. else
  300. if reportPmtMinusMean; ylim([-1 2.5]); else; ylim([0 2.5]); end
  301. end
  302. if ll==3; xlabel('Frequency [Hz]'); end
  303. if tt==1; ylabel('Baseline-Normalized Power');
  304. if strcmp(sVisualArea,'V1')
  305. if strcmpi(sSubjectName,'Wyman')
  306. text(3,7.5,['n=' num2str(numPooledChs) ';']);
  307. else
  308. text(3,3.5,['n=' num2str(numPooledChs) ';']);
  309. end
  310. else
  311. text(3,2.3,['n=' num2str(numPooledChs) ';']);
  312. end
  313. end
  314. if tt<6
  315. pValuesVec=nan(1,sum(freqAxis<100));
  316. for ff=1:sum(freqAxis<100)
  317. pValuesVec(ff)=signrank(currSpectPowRF(:,ff),currSpectPowOUT(:,ff));
  318. end
  319. [~,~,~,pValuesVecFDR]=fdr_bh(pValuesVec);
  320. pValuesBar05FDR=nan(1,sum(freqAxis<100));
  321. if reportPmtMinusMean
  322. pValuesBar05FDR(pValuesVecFDR<=.05)=-1;
  323. else
  324. pValuesBar05FDR(pValuesVecFDR<=.05)=0;
  325. end
  326. plot(freqAxis(freqAxis<100),pValuesBar05FDR,'color',[0 0 0],'linewidth',2.5);
  327. end
  328. set(gca,'XTick',0:20:100);%set(gca,'XTickLabel',{'0','10','20','30','40','50','60','70','80','90','100'});
  329. end
  330. end
  331. legend('RF','OUT','p\leq 0.05');
  332. supertitle([sSubjectName ' ' sVisualArea ' - Avg across PENs - LFPs Spectral Power']);
  333. end
  334. %% PLOT MEAN ACROSS PENS PRE-FIRST-DIM OUT=OUT1/2+OUT2/2, LAYERS POOLED, POSTSTIM OVERLAYED (DASHED)
  335. if plotPmtsPenAvgOutMeanPoolLayersPreFirstDimOverlayed
  336. figure('units','normalized','outerposition',[0 0 1 1]);
  337. tt=2; % Pick Stationary time window
  338. currSpectPowRF=[PoolPmtStruct.(lamLayerTag{1}).RF.([timeWinTag{tt} 'ZSc']);...
  339. PoolPmtStruct.(lamLayerTag{2}).RF.([timeWinTag{tt} 'ZSc']);...
  340. PoolPmtStruct.(lamLayerTag{3}).RF.([timeWinTag{tt} 'ZSc'])];
  341. currSpectPowOUT=[nanmean(cat(4,PoolPmtStruct.(lamLayerTag{1}).OUT1.([timeWinTag{tt} 'ZSc']),...
  342. PoolPmtStruct.(lamLayerTag{1}).OUT2.([timeWinTag{tt} 'ZSc'])),4);
  343. nanmean(cat(4,PoolPmtStruct.(lamLayerTag{2}).OUT1.([timeWinTag{tt} 'ZSc']),...
  344. PoolPmtStruct.(lamLayerTag{2}).OUT2.([timeWinTag{tt} 'ZSc'])),4);
  345. nanmean(cat(4,PoolPmtStruct.(lamLayerTag{3}).OUT1.([timeWinTag{tt} 'ZSc']),...
  346. PoolPmtStruct.(lamLayerTag{3}).OUT2.([timeWinTag{tt} 'ZSc'])),4)];
  347. numPooledChs=size(currSpectPowRF,1);
  348. if reportPmtMinusMean
  349. plot(freqAxis,zeros(1,length(freqAxis)),'k');
  350. end
  351. plotmsem(freqAxis,currSpectPowRF,'r:');
  352. plotmsem(freqAxis,currSpectPowOUT,'b:');
  353. currSpectPowPFDRF=[PoolPmtStruct.(lamLayerTag{1}).RF.PreFirstDimZSc;...
  354. PoolPmtStruct.(lamLayerTag{2}).RF.PreFirstDimZSc;...
  355. PoolPmtStruct.(lamLayerTag{3}).RF.PreFirstDimZSc];
  356. currSpectPowPFDOUT=[nanmean(cat(4,PoolPmtStruct.(lamLayerTag{1}).OUT1.PreFirstDimZSc,...
  357. PoolPmtStruct.(lamLayerTag{1}).OUT2.PreFirstDimZSc),4);...
  358. nanmean(cat(4,PoolPmtStruct.(lamLayerTag{2}).OUT1.PreFirstDimZSc,...
  359. PoolPmtStruct.(lamLayerTag{2}).OUT2.PreFirstDimZSc),4);...
  360. nanmean(cat(4,PoolPmtStruct.(lamLayerTag{3}).OUT1.PreFirstDimZSc,...
  361. PoolPmtStruct.(lamLayerTag{3}).OUT2.PreFirstDimZSc),4)];
  362. plotmsem(freqAxis,currSpectPowPFDRF,'r');
  363. plotmsem(freqAxis,currSpectPowPFDOUT,'b');
  364. title([timeWinTag{tt} ' - ' lamLayerTag{ll} ' Layer']);
  365. xlim([0 100]);
  366. if strcmp(sVisualArea,'V1')
  367. if reportPmtMinusMean
  368. if strcmpi(sSubjectName(end),'1')
  369. ylim([-1 8]);
  370. else
  371. ylim([-1 6]);
  372. end
  373. else
  374. ylim([0 8]);
  375. end
  376. else
  377. if reportPmtMinusMean
  378. ylim([-1 2.5]);
  379. else
  380. ylim([0 2.5]);
  381. end
  382. end
  383. if ll==3; xlabel('Frequency [Hz]'); end
  384. pValuesVec=nan(1,sum(freqAxis<=100));
  385. for ff=1:sum(freqAxis<100)
  386. pValuesVec(ff)=signrank(currSpectPowPFDRF(:,ff),currSpectPowPFDOUT(:,ff));
  387. end
  388. [~,~,~,pValuesVecFDR]=fdr_bh(pValuesVec);
  389. pValuesBar05FDR=nan(1,sum(freqAxis<=100));
  390. if reportPmtMinusMean
  391. pValuesBar05FDR(pValuesVecFDR<=.05)=-.5;
  392. else
  393. pValuesBar05FDR(pValuesVecFDR<=.05)=0;
  394. end
  395. plot(freqAxis(freqAxis<100),pValuesBar05FDR,'color',[0 0 0],'linewidth',2.5);
  396. set(gca,'XTick',0:20:100); %set(gca,'XTickLabel',{'0','10','20','30','40','50','60','70','80','90','100'});
  397. supertitle([sSubjectName ' ' sVisualArea ' - Avg across PENs - LFPs Spectral Power']);
  398. end
  399. end