D_Figure4.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. %% Plotting Heatmaps and average PSTH for sequence of event in DT5, FR5 and FS5
  2. % edited on june 2019 to only include sucrose rats in DT5 data set
  3. % do average first/last 3 session on PSTH instead of all sessions
  4. clc;clear all; close all;
  5. task_name={'DT5','FR5','FS5'};
  6. task_Dataset={'R_DT5','R_FR5','R_FS5'};
  7. BSIZE=0.01; %Do not change
  8. Dura=[-25 20]; Tm=Dura(1):BSIZE:Dura(2);
  9. Eventnames{1}={'';'LI';'';'LP1';'';'LP2';'';'LP3';'';'LP4';'';'LP5';'';'PE'};
  10. Eventnames{2}={'';'LP1';'';'LP2';'';'LP3';'';'LP4';'';'LP5';'';'PE'};
  11. Eventnames{3}={'';'LP1';'';'LP2';'';'LP3';'';'LP4';'';'LP5';'';'PE'};
  12. %% --- --- Plotting color-coded and average PSTHs --- ---
  13. BrainRegion=[10 20]; %10 for DLS, 20 for DMS
  14. % ----------- COLORS ---------
  15. myblue=[0 113/255 188/255];
  16. Clim=[-2 2];%ColorMap
  17. Xevent=[-0.25 0.25];
  18. Yaxis=[-1 3];Xaxis=[1 357];
  19. Ishow=find(Tm>=Xevent(1) & Tm<=Xevent(2));
  20. % for stat
  21. Ishow1(1,:)=find(Tm>=Xevent(1) & Tm<=0);
  22. Ishow1(2,:)=find(Tm>=0 & Tm<=Xevent(2));
  23. Combined_Table_allTask=[];allTask_ID=[];
  24. %% ------------------------------------Main program ------------------------------------------------------------------------------------------------------------------------
  25. figure;
  26. for task=1:length(task_Dataset)
  27. %generate concat file
  28. clear R DLSselectionTRN DMSselectionTRN Celltype SesCelltype
  29. load(task_Dataset{task})
  30. DLSconcat_ACQ_first3=[];DMSconcat_ACQ_first3=[];DLSconcat_ACQ_last3=[]; DMSconcat_ACQ_last3=[];DLSconcat_ACQ_all=[];DMSconcat_ACQ_all=[];
  31. for k=1:size(R.Ses,2)
  32. DLSselectionTRN=R.Ses(k).Coord(:,4)==BrainRegion(1) & R.Ses(k).TRN(:,1)~=0 & SesCelltype(k).Celltype(:,1)==1 ;
  33. DMSselectionTRN=R.Ses(k).Coord(:,4)==BrainRegion(2) & R.Ses(k).TRN(:,1)~=0 & SesCelltype(k).Celltype(:,1)==1;
  34. NbN{task}(k,1)=sum(DLSselectionTRN)*100/sum(R.Ses(k).Coord(:,4)==BrainRegion(1) & SesCelltype(k).Celltype(:,1)==1);
  35. NbN{task}(k,2)=100-NbN{1}(k,1);
  36. NbN{task}(k,3)=sum(DMSselectionTRN)*100/sum(R.Ses(k).Coord(:,4)==BrainRegion(2) & SesCelltype(k).Celltype(:,1)==1);
  37. NbN{task}(k,4)=100-NbN{1}(k,3);
  38. DLSconcat_ACQ=[];DMSconcat_ACQ=[];
  39. if task==1
  40. DLSconcat_ACQ = cat(2,DLSconcat_ACQ,R.Ses(k).Ev(7).PSTHz(DLSselectionTRN,Ishow));
  41. DMSconcat_ACQ = cat(2,DMSconcat_ACQ,R.Ses(k).Ev(7).PSTHz(DMSselectionTRN,Ishow));
  42. end
  43. for i=1:6
  44. DLSconcat_ACQ = cat(2,DLSconcat_ACQ,R.Ses(k).Ev(i).PSTHz(DLSselectionTRN,Ishow));
  45. DMSconcat_ACQ = cat(2,DMSconcat_ACQ,R.Ses(k).Ev(i).PSTHz(DMSselectionTRN,Ishow));
  46. end
  47. if k<4 %first 3 DT5 sessions
  48. DLSconcat_ACQ_first3=cat(1,DLSconcat_ACQ_first3,DLSconcat_ACQ);
  49. DMSconcat_ACQ_first3=cat(1,DMSconcat_ACQ_first3,DMSconcat_ACQ);
  50. end
  51. if k>(length(R.Ses)-3)
  52. DLSconcat_ACQ_last3=cat(1,DLSconcat_ACQ_last3,DLSconcat_ACQ);
  53. DMSconcat_ACQ_last3=cat(1,DMSconcat_ACQ_last3,DMSconcat_ACQ);
  54. end
  55. DLSconcat_ACQ_all=cat(1,DLSconcat_ACQ_all,DLSconcat_ACQ);
  56. DMSconcat_ACQ_all=cat(1,DMSconcat_ACQ_all,DMSconcat_ACQ);
  57. time=[1:1:size(DLSconcat_ACQ,2)];
  58. MeanDLS_ACQ{task}(k,:)=nanmean(DLSconcat_ACQ,1);
  59. MeanDMS_ACQ{task}(k,:)=nanmean(DMSconcat_ACQ,1);
  60. DLSsem1{task}(k,:)=nansem(DLSconcat_ACQ(:,time),1);
  61. DMSsem1{task}(k,:)=nansem(DMSconcat_ACQ(:,time),1);
  62. DLSnn{task}(k,1)=size(DLSconcat_ACQ,1);
  63. DMSnn{task}(k,1)=size(DMSconcat_ACQ,1);
  64. end
  65. MeanDLS_ACQ_first3=nanmean(DLSconcat_ACQ_first3,1);
  66. MeanDMS_ACQ_first3=nanmean(DMSconcat_ACQ_first3,1);
  67. DLSsem1_first3=nansem(DLSconcat_ACQ_first3,1);
  68. DMSsem1_first3=nansem(DMSconcat_ACQ_first3,1);
  69. MeanDLS_ACQ_last3=nanmean(DLSconcat_ACQ_last3,1);
  70. MeanDMS_ACQ_last3=nanmean(DMSconcat_ACQ_last3,1);
  71. DLSsem1_last3=nansem(DLSconcat_ACQ_last3,1);
  72. DMSsem1_last3=nansem(DMSconcat_ACQ_last3,1);
  73. MeanDLS_ACQ_all=nanmean(DLSconcat_ACQ_all,1);
  74. MeanDMS_ACQ_all=nanmean(DMSconcat_ACQ_all,1);
  75. DLSsem1_all=nansem(DLSconcat_ACQ_all,1);
  76. DMSsem1_all=nansem(DMSconcat_ACQ_all,1);
  77. %% table for stat
  78. Combined_Session=[]; Combined_Table=[];Combined_region=[];
  79. for k=1:size(R.Ses,2)
  80. DSconcat_ACQ=[];Table=[];
  81. for l=1:6
  82. DSconcat_ACQ = cat(2,DSconcat_ACQ,R.Ses(k).Ev(l).PSTHz(:,Ishow));
  83. end
  84. selection=sum(isnan(DSconcat_ACQ),2)==0 & R.Ses(k).Coord(:,4)~=0 & R.Ses(k).TRN(:,1)~=0 & SesCelltype(k).Celltype(:,1)==1;
  85. for l=1:6
  86. for m=1:2
  87. Table=cat(2,Table,nanmean(R.Ses(k).Ev(l).PSTHz(selection,Ishow1(m,:)),2));
  88. end
  89. end
  90. Combined_Table=cat(1,Combined_Table,Table);
  91. Combined_Session=cat(1,Combined_Session,k*ones(size(Table,1),1));
  92. Combined_region=cat(1,Combined_region,R.Ses(k).Coord(selection,4));
  93. end
  94. Combined_Table=[Combined_Session Combined_region Combined_Table];
  95. Combined_Table_allTask=cat(1,Combined_Table_allTask,Combined_Table);
  96. allTask_ID=cat(1,allTask_ID, task*ones(length(Combined_Table),1));
  97. TableActivity=cat(2,allTask_ID,Combined_Table_allTask);
  98. %% Heatmaps
  99. if task>1
  100. Xaxis=[1 306];
  101. end
  102. figure(1)
  103. subplot(3,3,1+3*(task-1))
  104. imagesc(time,[1 size(MeanDLS_ACQ{task},1)],MeanDLS_ACQ{task},Clim); %colorbar;axis tight;
  105. colormap(parula);
  106. hold on
  107. plot([51 51],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  108. plot([102 102],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  109. plot([153 153],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  110. plot([204 204],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  111. plot([255 255],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  112. plot([306 306],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  113. hold off
  114. set(gca,'XTick',0:25.5:size(MeanDLS_ACQ{task},2));
  115. set(gca,'xticklabel',Eventnames{task})
  116. ylabel('sessions');
  117. subplot(3,3,2+3*(task-1))
  118. imagesc(time,[1 size(MeanDMS_ACQ{task},1)],MeanDMS_ACQ{task},Clim); %colorbar;axis tight;
  119. colormap(parula);
  120. hold on
  121. plot([51 51],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  122. plot([102 102],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  123. plot([153 153],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  124. plot([204 204],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  125. plot([255 255],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  126. plot([306 306],[size(MeanDLS_ACQ{task},1)+0.5 0.5],'k')
  127. set(gca,'XTick',0:25.5:size(MeanDLS_ACQ{task},2));
  128. set(gca,'xticklabel',Eventnames{task})
  129. hold off
  130. subplot(3,3,3+3*(task-1))
  131. DLSpsth=MeanDLS_ACQ_all;
  132. DLSsem=DLSsem1_all;
  133. DLSup=DLSpsth+DLSsem;
  134. DLSdown=DLSpsth-DLSsem;
  135. hold on;
  136. patch([time,time(end:-1:1)],[DLSup,DLSdown(end:-1:1)],myblue,'EdgeColor','none');alpha(0.5);
  137. g1=plot(time,DLSpsth,'Color',myblue,'linewidth',1.5);
  138. DMSpsth=MeanDMS_ACQ_all;
  139. DMSsem=DMSsem1_all;
  140. DMSup=DMSpsth+DMSsem;
  141. DMSdown=DMSpsth-DMSsem;
  142. hold on;
  143. patch([time,time(end:-1:1)],[DMSup,DMSdown(end:-1:1)],'r','EdgeColor','none');alpha(0.5);
  144. g2=plot(time,DMSpsth,'r','linewidth',1.5);
  145. plot([0 357], [0 0],'LineStyle',':','Color','k');
  146. plot([51 51],[-1 3],'LineStyle',':','Color','k')
  147. plot([102 102],[-1 3],'LineStyle',':','Color','k')
  148. plot([153 153],[-1 3],'LineStyle',':','Color','k')
  149. plot([204 204],[-1 3],'LineStyle',':','Color','k')
  150. plot([255 255],[-1 3],'LineStyle',':','Color','k')
  151. plot([306 306],[-1 3],'LineStyle',':','Color','k')
  152. axis([Xaxis,Yaxis]);
  153. set(gca,'XTick',0:25.5:size(MeanDLS_ACQ,2));
  154. set(gca,'xticklabel',Eventnames{task})
  155. ylabel('z-score');
  156. trace=cat(2,g1,g2);
  157. label{1}=['DLS'];label{2}=['DMS'];
  158. legend(trace,label,'location','northeast');
  159. hold off
  160. %% average PSTH
  161. figure(2)
  162. subplot(6,1,1+2*(task-1))
  163. DLSpsth=MeanDLS_ACQ_first3;
  164. DLSsem=DLSsem1_first3;
  165. DLSup=DLSpsth+DLSsem;
  166. DLSdown=DLSpsth-DLSsem;
  167. hold on;
  168. patch([time,time(end:-1:1)],[DLSup,DLSdown(end:-1:1)],myblue,'EdgeColor','none');alpha(0.5);
  169. g1=plot(time,DLSpsth,'Color',myblue,'linewidth',1.5);
  170. DMSpsth=MeanDMS_ACQ_first3;
  171. DMSsem=DMSsem1_first3;
  172. DMSup=DMSpsth+DMSsem;
  173. DMSdown=DMSpsth-DMSsem;
  174. hold on;
  175. patch([time,time(end:-1:1)],[DMSup,DMSdown(end:-1:1)],'r','EdgeColor','none');alpha(0.5);
  176. g2=plot(time,DMSpsth,'r','linewidth',1.5);
  177. plot([0 357], [0 0],'LineStyle',':','Color','k');
  178. plot([51 51],[-1 3],'LineStyle',':','Color','k')
  179. plot([102 102],[-1 3],'LineStyle',':','Color','k')
  180. plot([153 153],[-1 3],'LineStyle',':','Color','k')
  181. plot([204 204],[-1 3],'LineStyle',':','Color','k')
  182. plot([255 255],[-1 3],'LineStyle',':','Color','k')
  183. plot([306 306],[-1 3],'LineStyle',':','Color','k')
  184. axis([Xaxis,Yaxis]);
  185. set(gca,'XTick',0:25.5:size(MeanDLS_ACQ,2));
  186. set(gca, 'XTickLabel', [])
  187. ylabel('z-score');
  188. trace=cat(2,g1,g2);
  189. label{1}=['DLS'];label{2}=['DMS'];
  190. legend(trace,label,'location','northeast');
  191. hold off
  192. subplot(6,1,2+2*(task-1))
  193. DLSpsth=MeanDLS_ACQ_last3;
  194. DLSsem=DLSsem1_last3;
  195. DLSup=DLSpsth+DLSsem;
  196. DLSdown=DLSpsth-DLSsem;
  197. hold on;
  198. patch([time,time(end:-1:1)],[DLSup,DLSdown(end:-1:1)],myblue,'EdgeColor','none');alpha(0.5);
  199. g1=plot(time,DLSpsth,'Color',myblue,'linewidth',1.5);
  200. DMSpsth=MeanDMS_ACQ_last3;
  201. DMSsem=DMSsem1_last3;
  202. DMSup=DMSpsth+DMSsem;
  203. DMSdown=DMSpsth-DMSsem;
  204. hold on;
  205. patch([time,time(end:-1:1)],[DMSup,DMSdown(end:-1:1)],'r','EdgeColor','none');alpha(0.5);
  206. g2=plot(time,DMSpsth,'r','linewidth',1.5);
  207. plot([0 357], [0 0],'LineStyle',':','Color','k');
  208. plot([51 51],[-1 3],'LineStyle',':','Color','k')
  209. plot([102 102],[-1 3],'LineStyle',':','Color','k')
  210. plot([153 153],[-1 3],'LineStyle',':','Color','k')
  211. plot([204 204],[-1 3],'LineStyle',':','Color','k')
  212. plot([255 255],[-1 3],'LineStyle',':','Color','k')
  213. plot([306 306],[-1 3],'LineStyle',':','Color','k')
  214. axis([Xaxis,Yaxis]);
  215. set(gca,'XTick',0:25.5:size(MeanDLS_ACQ,2));
  216. set(gca,'xticklabel',Eventnames{task})
  217. ylabel('z-score');
  218. end
  219. %% statistiques
  220. nbevent=[1:12];
  221. stat(1).condition{1}='TRN DT5';
  222. stat(2).condition{1}='TRN FR5';
  223. stat(3).condition{1}='TRN FS5';
  224. filename = 'ResultStat_Activity_Fig4.xlsx';
  225. for i=1:3
  226. selection=TableActivity(:,1)==i;
  227. tableSTAT=array2table(TableActivity(selection,2:end),'VariableNames',{'session','region','win1','win2','win3','win4','win5','win6','win7','win8','win9','win10','win11','win12'});
  228. tableSTAT.session=categorical(tableSTAT.session);
  229. tableSTAT.region=categorical(tableSTAT.region);
  230. rm_reg = fitrm(tableSTAT,'win1-win12~region*session','WithinDesign',nbevent');
  231. stat(i).ranovatbl_event = ranova(rm_reg);
  232. stat(i).Btw_ranovatbl_event = anova(rm_reg);
  233. writetable(stat(i).ranovatbl_event,filename,'Sheet',i,'Range','A1')
  234. writetable(stat(i).Btw_ranovatbl_event,filename,'Sheet',i,'Range','J1')
  235. end
  236. stat(4).condition={'3 tasks'};
  237. selection=TableActivity(:,2)<8; % Comparison tasks, sessions 1-7
  238. tableSTAT=array2table(TableActivity(selection,:),'VariableNames',{'task','session','region','win1','win2','win3','win4','win5','win6','win7','win8','win9','win10','win11','win12'});
  239. tableSTAT.session=categorical(tableSTAT.session);
  240. tableSTAT.region=categorical(tableSTAT.region);
  241. tableSTAT.task=categorical(tableSTAT.task);
  242. rm_reg = fitrm(tableSTAT,'win1-win12~task*session*region','WithinDesign',nbevent');
  243. stat(4).ranovatbl_event = ranova(rm_reg);
  244. stat(4).Btw_ranovatbl_event = anova(rm_reg);
  245. stat(4).posthoc = multcompare(rm_reg,'task', 'by', 'region');
  246. writetable(stat(4).ranovatbl_event,filename,'Sheet',4,'Range','A1')
  247. writetable(stat(4).Btw_ranovatbl_event,filename,'Sheet',4,'Range','J1')
  248. writetable(stat(4).posthoc,filename,'Sheet',4,'Range','R1')