E_generateFigure2.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. %% generate Figure 2.
  2. % Plotting Heatmaps all neurons 1st/last session early training and extended training
  3. % need R_light datafiles, Celltype datafiles to only include MSN, and TRN
  4. % datafiles to restrict analysis on TRN.
  5. clc;clear;close all
  6. Task=1;
  7. load('Rextendedtraining_light.mat');
  8. load('Celltype_extendedTraining.mat');
  9. load('TRN_DT5_extendedtrain.mat')
  10. %% --- --- Plotting color-coded and average PSTHs --- ---
  11. BrainRegion=[10 20]; %10 for DLS, 20 for DMS
  12. ExcInh=1; % 1 for excitations, 2 for inhibitions -- Used to find Exc or Inh onsets in R.Ev(.).Onsets
  13. Pstat=0.05;
  14. stepsize=0.3; % Used for the scatter plot projections
  15. % For COLOR-CODED PSTH only (not Average PSTH)
  16. Norm=0; % 0 = no norm - max accross all the selected neurons
  17. % 1 each neuron is normalized wh its own max
  18. % 2 for baseline substraction
  19. Sorting=4; % 1 to sort neurons by onset
  20. % 2 to sort neurons by duration
  21. % 3 to sort neurons by PeakTime
  22. % 4 to sort by class of neuron
  23. %for RExt ONLY! % 5 to sort by the magnitude of the cue response
  24. %for Cues ONLY! % 6 to sort by the magnitude of the RExt response
  25. Xaxis=[0 357];Yaxis=[-1 3];
  26. Xaxis1=[-0.25 0.25];
  27. Ishow=find(Tm>=Xaxis1(1) & Tm<=Xaxis1(2));
  28. % ----------- COLORS ---------
  29. myblue=[0 113/255 188/255];
  30. mypurple=[200/255 0 255/255];
  31. mydarkblue=[0 0/255 255/255];
  32. TickSize=[0.015 0.02];
  33. Eventnames={'';'LI';'';'LP1';'';'LP2';'';'LP3';'';'LP4';'';'LP5';'';'PE'};
  34. time=-0.25:0.25:3.25;time2=1:1:357;
  35. %% Indiv Neuron
  36. %analysis restricted on putative MSN. nonTRN included
  37. %concat with normalized data
  38. DSconcat_OT = Ev(7).PSTHz(:,Ishow);
  39. for i=1:6
  40. DSconcat_OT = cat(2,DSconcat_OT,Ev(i).PSTHz(:,Ishow));
  41. end
  42. DLSselection=Coord(:,4)==10 & Celltype(:,1)==1 & TRN(:,1)~=0;
  43. DMSselection=Coord(:,4)==20 & Celltype(:,1)==1 & TRN(:,1)~=0;
  44. LPwin=[52:280];
  45. binLP=mean(DSconcat_OT(:,LPwin),2);
  46. SEQwin=[26:331];
  47. binSEQ=mean(DSconcat_OT(TRN(:,1)~=0,SEQwin),2);
  48. TRN(TRN(:,1)~=0,2)=sign(binSEQ);
  49. DLSconcat_OT=DSconcat_OT(DLSselection,:);
  50. DMSconcat_OT=DSconcat_OT(DMSselection,:);
  51. %TMPdls=R.Class(DLSselection,1); TMPdms=R.Class(DMSselection,1);
  52. TMPdls=binLP(DLSselection,1);
  53. TMPdms=binLP(DMSselection,1);
  54. TMPdls(isnan(TMPdls))=0;
  55. TMPdms(isnan(TMPdms))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  56. [~,SORTimgDLS]=sort(TMPdls);[~,SORTimgDMS]=sort(TMPdms);
  57. DLSconcat_OT=DLSconcat_OT(SORTimgDLS,:);
  58. DMSconcat_OT=DMSconcat_OT(SORTimgDMS,:);
  59. subplot(9,8,[29 30 37 38 45 46 53 54 61 62 69 70])
  60. Clim=[-5 5];
  61. imagesc(time,[1 size(DLSconcat_OT,1)],DLSconcat_OT,Clim); %colorbar;axis tight;
  62. colormap(jet);
  63. hold on
  64. plot([0.25 0.25],[size(DLSconcat_OT,1)+0.5 0.5],'k')
  65. plot([0.75 0.75],[size(DLSconcat_OT,1)+0.5 0.5],'k')
  66. plot([1.25 1.25],[size(DLSconcat_OT,1)+0.5 0.5],'k')
  67. plot([1.75 1.75],[size(DLSconcat_OT,1)+0.5 0.5],'k')
  68. plot([2.25 2.25],[size(DLSconcat_OT,1)+0.5 0.5],'k')
  69. plot([2.75 2.75],[size(DLSconcat_OT,1)+0.5 0.5],'k')
  70. set(gca,'XTick',[0:0.25:3.25]);
  71. set(gca,'xticklabel',Eventnames)
  72. title('Extended training DLS');
  73. ylabel('neurons');
  74. hold off
  75. subplot(9,8,[31 32 39 40 47 48 55 56 63 64 71 72])
  76. imagesc(time,[1 size(DMSconcat_OT,1)],DMSconcat_OT,Clim); %colorbar;axis tight;
  77. colormap(jet);
  78. hold on
  79. plot([0.25 0.25],[size(DMSconcat_OT,1)+0.5 0.5],'k')
  80. plot([0.75 0.75],[size(DMSconcat_OT,1)+0.5 0.5],'k')
  81. plot([1.25 1.25],[size(DMSconcat_OT,1)+0.5 0.5],'k')
  82. plot([1.75 1.75],[size(DMSconcat_OT,1)+0.5 0.5],'k')
  83. plot([2.25 2.25],[size(DMSconcat_OT,1)+0.5 0.5],'k')
  84. plot([2.75 2.75],[size(DMSconcat_OT,1)+0.5 0.5],'k')
  85. set(gca,'XTick',[0:0.25:3.25]);
  86. set(gca,'xticklabel',Eventnames)
  87. title('Extended training DMS');
  88. ylabel('neurons');
  89. hold off
  90. %% Average OT PSTH
  91. subplot(9,8,[23 24])
  92. DLSpsth=nanmean(DLSconcat_OT,1);
  93. DLSsem=nanste(DLSconcat_OT,1);
  94. DLSup=DLSpsth+DLSsem;
  95. DLSdown=DLSpsth-DLSsem;
  96. hold on;
  97. patch([time2,time2(end:-1:1)],[DLSup,DLSdown(end:-1:1)],myblue,'EdgeColor','none');alpha(0.5);
  98. plot(time2,DLSpsth,'Color',myblue,'linewidth',1.5);
  99. DMSpsth=nanmean(DMSconcat_OT,1);
  100. DMSsem=nanste(DMSconcat_OT,1);
  101. DMSup=DMSpsth+DMSsem;
  102. DMSdown=DMSpsth-DMSsem;
  103. patch([time2,time2(end:-1:1)],[DMSup,DMSdown(end:-1:1)],'r','EdgeColor','none');alpha(0.5);
  104. plot(time2,DMSpsth,'r','linewidth',1.5);
  105. %plot([0 0], [-2 2.5],'LineStyle',':','Color','k');
  106. plot([0 357], [0 0],'LineStyle',':','Color','k');
  107. plot([51 51],Yaxis,'LineStyle',':','Color','k')
  108. plot([102 102],Yaxis,'LineStyle',':','Color','k')
  109. plot([153 153],Yaxis,'LineStyle',':','Color','k')
  110. plot([204 204],Yaxis,'LineStyle',':','Color','k')
  111. plot([255 255],Yaxis,'LineStyle',':','Color','k')
  112. plot([306 306],Yaxis,'LineStyle',':','Color','k')
  113. axis([Xaxis,Yaxis]);
  114. set(gca,'XTick',[0:25.5:357]);
  115. set(gca,'xticklabel',Eventnames)
  116. title('Extended training');
  117. ylabel('z-score');
  118. %% Pie Plot
  119. %proportion nonTRN excited inhibited
  120. %analysis restricted on putative MSN
  121. DLSselectionNonTRN=Coord(:,4)==10 & TRN(:,1)==0 & Celltype(:,1)==1;
  122. DLSselectionTRN_excited=Coord(:,4)==10 & TRN(:,1)~=0 & TRN(:,2)>0 & Celltype(:,1)==1;
  123. DLSselectionTRN_Inhibited=Coord(:,4)==10 & TRN(:,1)~=0 & TRN(:,2)<0 & Celltype(:,1)==1;
  124. DMSselectionNonTRN=Coord(:,4)==20 & TRN(:,1)==0 & Celltype(:,1)==1;
  125. DMSselectionTRN_excited=Coord(:,4)==20 & TRN(:,1)~=0 & TRN(:,2)>0 & Celltype(:,1)==1;
  126. DMSselectionTRN_Inhibited=Coord(:,4)==20 & TRN(:,1)~=0 & TRN(:,2)<0 & Celltype(:,1)==1;
  127. DLS_X(1)=sum(DLSselectionTRN_excited);
  128. DLS_X(2)=sum(DLSselectionTRN_Inhibited);
  129. DLS_X(3)=sum(DLSselectionNonTRN);
  130. DMS_X(1)=sum(DMSselectionTRN_excited);
  131. DMS_X(2)=sum(DMSselectionTRN_Inhibited);
  132. DMS_X(3)=sum(DMSselectionNonTRN);
  133. DLS_Percent=DLS_X*100./(sum(Coord(:,4)==10 & Celltype(:,1)==1));
  134. DMS_Percent=DMS_X*100./(sum(Coord(:,4)==20 & Celltype(:,1)==1));
  135. labels={'EXC','INH','non-TRN'};
  136. subplot(9,8,[11 12])
  137. bar(sum(DLS_Percent),'FaceColor',[0.9290 0.6940 0.1250]);
  138. hold on
  139. bar(sum(DLS_Percent(1:2)),'FaceColor',[0.8500 0.3250 0.0980]);
  140. bar(DLS_Percent(1),'FaceColor',[0 0.4470 0.7410]);
  141. axis([0.5 10.5 0 100 ])
  142. subplot(9,8,[19 20])
  143. bar(sum(DMS_Percent),'FaceColor',[0.9290 0.6940 0.1250]);
  144. hold on
  145. bar(sum(DMS_Percent(1:2)),'FaceColor',[0.8500 0.3250 0.0980]);
  146. bar(DMS_Percent(1),'FaceColor',[0 0.4470 0.7410]);
  147. axis([0.5 10.5 0 100 ])
  148. save('Rextendedtraining_light.mat','Coord','Erefnames','Ev','Ninfo','Tm','TRN')
  149. %% ACQUISITION DATASET
  150. clear Ev
  151. load('Rearlytraining_light.mat');
  152. load('Celltype_earlyTraining.mat');
  153. load('TRN_DT5_earlytrain.mat')
  154. for i=1:max(Celltype(:,1))
  155. selectionIN=Ses(i).Coord(:,4)~=0;
  156. selectsession=Celltype(:,1)==i;
  157. Ses(i).Celltype(1:length(selectionIN),1)=0;
  158. Ses(i).Celltype(selectionIN,1)=Celltype(selectsession,2);
  159. end
  160. %analysis restricted on putative MSN. nonTRN included
  161. %concat with normalized data
  162. titlegraph={'Early training 1st session','Early training last session'};
  163. for j=1:2
  164. vars={'TMPdls','TMPdms','binSEQ','binLP','DLSselection','DMSselection','DSconcat_ACQ','DLSconcat_ACQ','DMSconcat_ACQ'};
  165. clear(vars{:});
  166. if j==1
  167. k=4;
  168. else
  169. k=13;
  170. end
  171. DSconcat_ACQ = Ses(k).Ev(7).PSTHz(:,Ishow);
  172. for i=1:6
  173. DSconcat_ACQ = cat(2,DSconcat_ACQ,Ses(k).Ev(i).PSTHz(:,Ishow));
  174. end
  175. DLSselection=Ses(k).Coord(:,4)==10 & Ses(k).Celltype(:,1)==1 & sesTRN(k).TRN(:,1)~=0;
  176. DMSselection=Ses(k).Coord(:,4)==20 & Ses(k).Celltype(:,1)==1 & sesTRN(k).TRN(:,1)~=0;
  177. LPwin=[52:280];
  178. binLP=mean(DSconcat_ACQ(:,LPwin),2);
  179. SEQwin=[26:331];
  180. binSEQ=mean(DSconcat_ACQ(:,SEQwin),2);
  181. sesTRN(k).TRN(:,2)=sign(binSEQ);
  182. DLSconcat_ACQ=DSconcat_ACQ(DLSselection,:);
  183. DMSconcat_ACQ=DSconcat_ACQ(DMSselection,:);
  184. %TMPdls=R.Class(DLSselection,1); TMPdms=R.Class(DMSselection,1);
  185. TMPdls=binLP(DLSselection,1);
  186. TMPdms=binLP(DMSselection,1);
  187. TMPdls(isnan(TMPdls))=0;
  188. TMPdms(isnan(TMPdms))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  189. [~,SORTimgDLS]=sort(TMPdls);[~,SORTimgDMS]=sort(TMPdms);
  190. DLSconcat_ACQ=DLSconcat_ACQ(SORTimgDLS,:);
  191. DMSconcat_ACQ=DMSconcat_ACQ(SORTimgDMS,:);
  192. subplot(9,8,[25+(j-1)*24 26+(j-1)*24 33+(j-1)*24 34+(j-1)*24 41+(j-1)*24 42+(j-1)*24])
  193. Clim=[-5 5];
  194. imagesc(time,[1 size(DLSconcat_ACQ,1)],DLSconcat_ACQ,Clim); %colorbar;axis tight;
  195. colormap(jet);
  196. hold on
  197. plot([0.25 0.25],[size(DLSconcat_ACQ,1)+0.5 0.5],'k')
  198. plot([0.75 0.75],[size(DLSconcat_ACQ,1)+0.5 0.5],'k')
  199. plot([1.25 1.25],[size(DLSconcat_ACQ,1)+0.5 0.5],'k')
  200. plot([1.75 1.75],[size(DLSconcat_ACQ,1)+0.5 0.5],'k')
  201. plot([2.25 2.25],[size(DLSconcat_ACQ,1)+0.5 0.5],'k')
  202. plot([2.75 2.75],[size(DLSconcat_ACQ,1)+0.5 0.5],'k')
  203. set(gca,'XTick',[0:0.25:3.25]);
  204. set(gca,'xticklabel',Eventnames)
  205. title('DLS');
  206. ylabel('neurons');
  207. hold off
  208. subplot(9,8,[27+(j-1)*24 28+(j-1)*24 35+(j-1)*24 36+(j-1)*24 43+(j-1)*24 44+(j-1)*24])
  209. imagesc(time,[1 size(DMSconcat_ACQ,1)],DMSconcat_ACQ,Clim); %colorbar;axis tight;
  210. colormap(jet);
  211. hold on
  212. plot([0.25 0.25],[size(DMSconcat_ACQ,1)+0.5 0.5],'k')
  213. plot([0.75 0.75],[size(DMSconcat_ACQ,1)+0.5 0.5],'k')
  214. plot([1.25 1.25],[size(DMSconcat_ACQ,1)+0.5 0.5],'k')
  215. plot([1.75 1.75],[size(DMSconcat_ACQ,1)+0.5 0.5],'k')
  216. plot([2.25 2.25],[size(DMSconcat_ACQ,1)+0.5 0.5],'k')
  217. plot([2.75 2.75],[size(DMSconcat_ACQ,1)+0.5 0.5],'k')
  218. set(gca,'XTick',[0:0.25:3.25]);
  219. set(gca,'xticklabel',Eventnames)
  220. title('DMS');
  221. ylabel('neurons');
  222. hold off
  223. %% Average OT PSTH
  224. subplot(9,8,[7+(j-1)*8 8+(j-1)*8])
  225. DLSpsth=nanmean(DLSconcat_ACQ,1);
  226. DLSsem=nanste(DLSconcat_ACQ,1);
  227. DLSup=DLSpsth+DLSsem;
  228. DLSdown=DLSpsth-DLSsem;
  229. hold on;
  230. patch([time2,time2(end:-1:1)],[DLSup,DLSdown(end:-1:1)],myblue,'EdgeColor','none');alpha(0.5);
  231. plot(time2,DLSpsth,'Color',myblue,'linewidth',1.5);
  232. DMSpsth=nanmean(DMSconcat_ACQ,1);
  233. DMSsem=nanste(DMSconcat_ACQ,1);
  234. DMSup=DMSpsth+DMSsem;
  235. DMSdown=DMSpsth-DMSsem;
  236. patch([time2,time2(end:-1:1)],[DMSup,DMSdown(end:-1:1)],'r','EdgeColor','none');alpha(0.5);
  237. plot(time2,DMSpsth,'r','linewidth',1.5);
  238. %plot([0 0], [-2 2.5],'LineStyle',':','Color','k');
  239. plot([0 357], [0 0],'LineStyle',':','Color','k');
  240. plot([51 51],Yaxis,'LineStyle',':','Color','k')
  241. plot([102 102],Yaxis,'LineStyle',':','Color','k')
  242. plot([153 153],Yaxis,'LineStyle',':','Color','k')
  243. plot([204 204],Yaxis,'LineStyle',':','Color','k')
  244. plot([255 255],Yaxis,'LineStyle',':','Color','k')
  245. plot([306 306],Yaxis,'LineStyle',':','Color','k')
  246. axis([Xaxis,Yaxis]);
  247. set(gca,'XTick',[0:25.5:357]);
  248. set(gca,'xticklabel',Eventnames)
  249. title(titlegraph(j));
  250. ylabel('z-score');
  251. end
  252. %% Pie Plot
  253. %proportion nonTRN excited inhibited
  254. %analysis restricted on putative MSN
  255. for i=4:13
  256. DSconcat_ACQ = Ses(i).Ev(7).PSTHz(:,Ishow);
  257. for j=1:6
  258. DSconcat_ACQ = cat(2,DSconcat_ACQ,Ses(i).Ev(j).PSTHz(:,Ishow));
  259. end
  260. SEQwin=[26:331];
  261. binSEQ=nanmean(DSconcat_ACQ(:,SEQwin),2);
  262. sesTRN(i).TRN(:,2)=sign(binSEQ);
  263. DLSselectionNonTRN_ACQ=Ses(i).Coord(:,4)==10 & sesTRN(i).TRN(:,1)==0 & Ses(i).Celltype(:,1)==1;
  264. DLSselectionTRN_excited_ACQ=Ses(i).Coord(:,4)==10 & sesTRN(i).TRN(:,1)~=0 & sesTRN(i).TRN(:,2)>0 & Ses(i).Celltype(:,1)==1;
  265. DLSselectionTRN_Inhibited_ACQ=Ses(i).Coord(:,4)==10 & sesTRN(i).TRN(:,1)~=0 & sesTRN(i).TRN(:,2)<0 & Ses(i).Celltype(:,1)==1;
  266. DMSselectionNonTRN_ACQ=Ses(i).Coord(:,4)==20 & sesTRN(i).TRN(:,1)==0 & Ses(i).Celltype(:,1)==1;
  267. DMSselectionTRN_excited_ACQ=Ses(i).Coord(:,4)==20 & sesTRN(i).TRN(:,1)~=0 & sesTRN(i).TRN(:,2)>0 & Ses(i).Celltype(:,1)==1;
  268. DMSselectionTRN_Inhibited_ACQ=Ses(i).Coord(:,4)==20 & sesTRN(i).TRN(:,1)~=0 & sesTRN(i).TRN(:,2)<0 & Ses(i).Celltype(:,1)==1;
  269. DLS_X_ACQ(i-3,1)=sum(DLSselectionTRN_excited_ACQ);
  270. DLS_X_ACQ(i-3,2)=sum(DLSselectionTRN_Inhibited_ACQ);
  271. DLS_X_ACQ(i-3,3)=sum(DLSselectionNonTRN_ACQ);
  272. DMS_X_ACQ(i-3,1)=sum(DMSselectionTRN_excited_ACQ);
  273. DMS_X_ACQ(i-3,2)=sum(DMSselectionTRN_Inhibited_ACQ);
  274. DMS_X_ACQ(i-3,3)=sum(DMSselectionNonTRN_ACQ);
  275. DLS_Percent_ACQ(i-3,:)=DLS_X_ACQ(i-3,:)*100./(sum(Ses(i).Coord(:,4)==10 & Ses(i).Celltype(:,1)==1));
  276. DMS_Percent_ACQ(i-3,:)=DMS_X_ACQ(i-3,:)*100./(sum(Ses(i).Coord(:,4)==20 & Ses(i).Celltype(:,1)==1));
  277. end
  278. labels={'EXC','INH','non-TRN'};
  279. subplot(9,8,[9 10])
  280. bar(DLS_Percent_ACQ,1,'stacked');
  281. axis([0.5 10.5 0 100 ])
  282. subplot(9,8,[17 18])
  283. bar(DMS_Percent_ACQ,1,'stacked');
  284. axis([0.5 10.5 0 100 ])
  285. save('Rearlytraining_light.mat','Erefnames','Ses','Tm')
  286. save('TRN_DT5_earlytrain.mat','sesTRN')