I_generateFigure8_SensitivityDeval.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. %% generate figure 8
  2. clc;clear;close all;
  3. load('Rextendedtraining_light.mat');
  4. load('RatID_extendedtraining.mat'); %% column 1 = rat ID, column 2 = habit ID; 0=goal-directed / 1=habit
  5. load('Celltype_extendedTraining.mat');
  6. load('TRN_DT5_extendedtrain.mat')
  7. load('table_OT.mat')
  8. %% --- --- Plotting color-coded and average PSTHs --- ---
  9. BrainRegion=[10 20]; %10 for DLS, 20 for DMS
  10. Xaxis=[0 357];Yaxis=[-2 5];
  11. Xaxis1=[-0.25 0.25];
  12. Ishow=find(Tm>=Xaxis1(1) & Tm<=Xaxis1(2));
  13. % ----------- COLORS ---------
  14. myblue=[0 113/255 188/255];
  15. mypurple=[200/255 0 255/255];
  16. mydarkblue=[0 0/255 255/255];
  17. TickSize=[0.015 0.02];
  18. Eventnames={'';'LI';'';'LP1';'';'LP2';'';'LP3';'';'LP4';'';'LP5';'';'PE'};
  19. titlegraph={'Extended Training - sensitive', 'Extended Training - insensitive'};
  20. time=-0.25:0.25:3.25;time2=1:1:357;
  21. %% Extended training - Average psTH
  22. %analysis restricted on putative MSN. nonTRN included.
  23. %concat with normalized data
  24. DSconcat_OT = Ev(7).PSTHz(:,Ishow);
  25. for i=1:6
  26. DSconcat_OT = cat(2,DSconcat_OT,Ev(i).PSTHz(:,Ishow));
  27. end
  28. for i=1:2 %loop through habit/not habit neurons
  29. DLSselection=Coord(:,4)==10 & Celltype(:,1)==1 & TRN(:,1)~=0 & RatID(:,2)==i-1;
  30. DMSselection=Coord(:,4)==20 & Celltype(:,1)==1 & TRN(:,1)~=0 & RatID(:,2)==i-1;
  31. LPwin=[52:280];
  32. binLP=mean(DSconcat_OT(:,LPwin),2);
  33. SEQwin=[26:331];
  34. binSEQ=mean(DSconcat_OT(TRN(:,1)~=0,SEQwin),2);
  35. TRN(TRN(:,1)~=0,2)=sign(binSEQ);
  36. DLSconcat_OT=DSconcat_OT(DLSselection,:);
  37. DMSconcat_OT=DSconcat_OT(DMSselection,:);
  38. subplot(2,3,3+(i-1)*3)
  39. DLSpsth=nanmean(DLSconcat_OT,1);
  40. DLSsem=nanste(DLSconcat_OT,1);
  41. DLSup=DLSpsth+DLSsem;
  42. DLSdown=DLSpsth-DLSsem;
  43. hold on;
  44. patch([time2,time2(end:-1:1)],[DLSup,DLSdown(end:-1:1)],myblue,'EdgeColor','none');alpha(0.5);
  45. g1=plot(time2,DLSpsth,'Color',myblue,'linewidth',1.5);
  46. DMSpsth=nanmean(DMSconcat_OT,1);
  47. DMSsem=nanste(DMSconcat_OT,1);
  48. DMSup=DMSpsth+DMSsem;
  49. DMSdown=DMSpsth-DMSsem;
  50. patch([time2,time2(end:-1:1)],[DMSup,DMSdown(end:-1:1)],'r','EdgeColor','none');alpha(0.5);
  51. g2=plot(time2,DMSpsth,'r','linewidth',1.5);
  52. %plot([0 0], [-2 2.5],'LineStyle',':','Color','k');
  53. plot([0 357], [0 0],'LineStyle',':','Color','k');
  54. plot([51 51],[-2 5],'LineStyle',':','Color','k')
  55. plot([102 102],[-2 5],'LineStyle',':','Color','k')
  56. plot([153 153],[-2 5],'LineStyle',':','Color','k')
  57. plot([204 204],[-2 5],'LineStyle',':','Color','k')
  58. plot([255 255],[-2 5],'LineStyle',':','Color','k')
  59. plot([306 306],[-2 5],'LineStyle',':','Color','k')
  60. axis([Xaxis,Yaxis]);
  61. set(gca,'XTick',[0:25.5:357]);
  62. set(gca,'xticklabel',Eventnames)
  63. traces=cat(2,g1,g2);
  64. labels={'DLS','DMS'};
  65. ylabel('z-score');
  66. legend(traces,labels)
  67. title(titlegraph(i))
  68. end
  69. DSconcat_OT = Ev(7).PSTHz(:,Ishow);
  70. for i=1:6
  71. DSconcat_OT = cat(2,DSconcat_OT,Ev(i).PSTHz(:,Ishow));
  72. end
  73. LPwin=[52:280];
  74. binLP=mean(DSconcat_OT(:,LPwin),2);
  75. %% heatmap Extended training neurons
  76. figure(2)
  77. titleplot={'DLS sensitive', 'DMS sensitive', 'DLS insensitive', 'DMS insensitive'};
  78. for i=1:max(table_OT(:,6))
  79. nbplottitle=0;
  80. for j=1:2 %loop thru habit profile
  81. for k=1:2 %loop thru region
  82. nbplottitle=nbplottitle+1;
  83. selection=Coord(:,4)==k*10 & RatID(:,2)==j-1 & table_OT(:,6)==i;
  84. DSconcat_Class_OT=DSconcat_OT(selection,:);
  85. %TMPdls=R.Class(DLSselection,1); TMPdms=R.Class(DMSselection,1);
  86. TMPds=binLP(selection,1);
  87. TMPds(isnan(TMPds))=0;
  88. [~,SORTimgDS]=sort(TMPds);[~,SORTimgDS]=sort(TMPds);
  89. DSconcat_Class_OT=DSconcat_Class_OT(SORTimgDS,:);
  90. subplot(4,5,1+(i-1)+10*(k-1)+5*(j-1))
  91. Clim=[-5 5];
  92. [nr,nc] = size(DSconcat_Class_OT);
  93. imagesc(time,[1 size(DSconcat_Class_OT,1)],DSconcat_Class_OT,Clim); %colorbar;axis tight;
  94. colormap(jet);
  95. hold on
  96. plot([0.25 0.25],[size(DSconcat_Class_OT,1)+0.5 0.5],'k')
  97. plot([0.75 0.75],[size(DSconcat_Class_OT,1)+0.5 0.5],'k')
  98. plot([1.25 1.25],[size(DSconcat_Class_OT,1)+0.5 0.5],'k')
  99. plot([1.75 1.75],[size(DSconcat_Class_OT,1)+0.5 0.5],'k')
  100. plot([2.25 2.25],[size(DSconcat_Class_OT,1)+0.5 0.5],'k')
  101. plot([2.75 2.75],[size(DSconcat_Class_OT,1)+0.5 0.5],'k')
  102. set(gca,'XTick',[0:0.25:3.25]);
  103. set(gca,'xticklabel',Eventnames)
  104. ylabel('neurons');
  105. title(titleplot{nbplottitle})
  106. hold off
  107. end
  108. end
  109. end
  110. %% EARLY TRAININIG DATASET - average PSTH
  111. clear Ev
  112. load ('Rearlytraining_light.mat');
  113. load ('Celltype_earlyTraining.mat');
  114. load('TRN_DT5_earlytrain.mat')
  115. load('RatID_earlytraining.mat');
  116. load('table_ACQ.mat')
  117. for i=1:max(Celltype(:,1))
  118. selectionIN=Ses(i).Coord(:,4)~=0;
  119. selectsession=Celltype(:,1)==i;
  120. Ses(i).Celltype(1:length(selectionIN),1)=0;
  121. Ses(i).Celltype(selectionIN,1)=Celltype(selectsession,2);
  122. Ses(i).RatID(selectionIN,1)=RatID_ACQ(selectsession,1);
  123. end
  124. %analysis restricted on putative MSN. nonTRN included
  125. %concat with normalized data
  126. nbplot=0;
  127. figure(1)
  128. titlegraph={'1st session - sensitive','last session - sensitive', '1st session - insensitive','last session - insensitive'};
  129. for l=1:2 %loop thru habit profile
  130. for j=1:2 %loop thru 1st last session
  131. vars={'TMPdls','TMPdms','binSEQ','binLP','DLSselection','DMSselection','DSconcat_ACQ','DLSconcat_ACQ','DMSconcat_ACQ'};
  132. clear(vars{:});
  133. nbplot=nbplot+1;
  134. if j==1
  135. k=4;
  136. else
  137. k=13;
  138. end
  139. DSconcat_ACQ = Ses(k).Ev(7).PSTHz(:,Ishow);
  140. for i=1:6
  141. DSconcat_ACQ = cat(2,DSconcat_ACQ,Ses(k).Ev(i).PSTHz(:,Ishow));
  142. end
  143. DLSselection=Ses(k).Coord(:,4)==10 & Ses(k).Celltype(:,1)==1 & sesTRN(k).TRN(:,1)~=0 & Ses(k).RatID(:,1)==l-1;
  144. DMSselection=Ses(k).Coord(:,4)==20 & Ses(k).Celltype(:,1)==1 & sesTRN(k).TRN(:,1)~=0 & Ses(k).RatID(:,1)==l-1;
  145. LPwin=[52:280];
  146. binLP=mean(DSconcat_ACQ(:,LPwin),2);
  147. SEQwin=[26:331];
  148. binSEQ=mean(DSconcat_ACQ(:,SEQwin),2);
  149. sesTRN(k).TRN(:,2)=sign(binSEQ);
  150. DLSconcat_ACQ=DSconcat_ACQ(DLSselection,:);
  151. DMSconcat_ACQ=DSconcat_ACQ(DMSselection,:);
  152. %% Average OT PSTH
  153. traces=[];
  154. subplot(2,3,1+(j-1)+3*(l-1))
  155. DLSpsth=nanmean(DLSconcat_ACQ,1);
  156. DLSsem=nanste(DLSconcat_ACQ,1);
  157. DLSup=DLSpsth+DLSsem;
  158. DLSdown=DLSpsth-DLSsem;
  159. hold on;
  160. patch([time2,time2(end:-1:1)],[DLSup,DLSdown(end:-1:1)],myblue,'EdgeColor','none');alpha(0.5);
  161. g1=plot(time2,DLSpsth,'Color',myblue,'linewidth',1.5);
  162. DMSpsth=nanmean(DMSconcat_ACQ,1);
  163. DMSsem=nanste(DMSconcat_ACQ,1);
  164. DMSup=DMSpsth+DMSsem;
  165. DMSdown=DMSpsth-DMSsem;
  166. patch([time2,time2(end:-1:1)],[DMSup,DMSdown(end:-1:1)],'r','EdgeColor','none');alpha(0.5);
  167. g2=plot(time2,DMSpsth,'r','linewidth',1.5);
  168. %plot([0 0], [-2 2.5],'LineStyle',':','Color','k');
  169. plot([0 357], [0 0],'LineStyle',':','Color','k');
  170. plot([51 51],[-2 5],'LineStyle',':','Color','k')
  171. plot([102 102],[-2 5],'LineStyle',':','Color','k')
  172. plot([153 153],[-2 5],'LineStyle',':','Color','k')
  173. plot([204 204],[-2 5],'LineStyle',':','Color','k')
  174. plot([255 255],[-2 5],'LineStyle',':','Color','k')
  175. plot([306 306],[-2 5],'LineStyle',':','Color','k')
  176. axis([Xaxis,Yaxis]);
  177. set(gca,'XTick',[0:25.5:357]);
  178. set(gca,'xticklabel',Eventnames)
  179. traces=cat(2,g1,g2);
  180. labels={'DLS','DMS'};
  181. ylabel('z-score');
  182. legend(traces,labels)
  183. title(titlegraph(nbplot))
  184. end
  185. end
  186. %% Early training data set - heatmaps
  187. %Xaxis=[0 357];Yaxis=[-1 3];
  188. Xaxis1=[-0.25 0.25];
  189. Ishow=find(Tm>=Xaxis1(1) & Tm<=Xaxis1(2));
  190. time=-0.25:0.25:3.25;
  191. Eventnames={'LI';'';'LP1';'';'LP2';'';'LP3';'';'LP4';'';'LP5';'';'PE';''};
  192. for i=1:max(Celltype(:,1))
  193. selectionIN=Ses(i).Coord(:,4)~=0;
  194. selectsession=Celltype(:,1)==i;
  195. Ses(i).Celltype(1:length(selectionIN),1)=0;
  196. Ses(i).Celltype(selectionIN,1)=Celltype(selectsession,2);
  197. Ses(i).RatID(selectionIN,1)=RatID_ACQ(selectsession,1);
  198. end
  199. figure
  200. for i=1:max(table_ACQ(:,5))
  201. nbtitle=0;
  202. for j=1:2 %loop thru habit profile
  203. for k=1:2 %loop thru region
  204. nbtitle=nbtitle+1;
  205. for l=4:13 %loop thru session
  206. DSconcat_ACQ=[];
  207. selection=Ses(l).Coord(:,4)==k*10 & Ses(l).Celltype(:,1)==1 & Ses(l).RatID(:,1)==j-1 & Ses(l).Class(:,1)==i;
  208. DSconcat_ACQ = Ses(l).Ev(7).PSTHz(selection,Ishow);
  209. for m=1:6
  210. DSconcat_ACQ = cat(2,DSconcat_ACQ,Ses(l).Ev(m).PSTHz(selection,Ishow));
  211. end
  212. MeanDS.img(l-3,:)=nanmean(DSconcat_ACQ,1);
  213. if j==1
  214. groupGD(k).region(l-3,i)=sum(selection);
  215. else
  216. groupHAB(k).region(l-3,i)=sum(selection);
  217. end
  218. end
  219. subplot(4,5,1+(i-1)+10*(k-1)+5*(j-1))
  220. Clim=[-5 5];
  221. imagesc(time,[1 size(MeanDS.img,1)],MeanDS.img,Clim); %colorbar;axis tight;
  222. colormap(jet);
  223. hold on
  224. plot([0.25 0.25],[size(MeanDS.img,1)+0.5 0.5],'k')
  225. plot([0.75 0.75],[size(MeanDS.img,1)+0.5 0.5],'k')
  226. plot([1.25 1.25],[size(MeanDS.img,1)+0.5 0.5],'k')
  227. plot([1.75 1.75],[size(MeanDS.img,1)+0.5 0.5],'k')
  228. plot([2.25 2.25],[size(MeanDS.img,1)+0.5 0.5],'k')
  229. plot([2.75 2.75],[size(MeanDS.img,1)+0.5 0.5],'k')
  230. set(gca,'XTick',[0:0.25:3.25]);
  231. set(gca,'xticklabel',Eventnames)
  232. ylabel('neurons');
  233. title(titleplot(nbtitle));
  234. hold off
  235. end
  236. end
  237. end