d_Fig2S2S3S5EventsBins.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. clear all;
  2. load ('R_2R.mat');
  3. %get parameters
  4. BinBase=R_2R.Param.BinBase;
  5. BinDura=R_2R.Param.BinDura;
  6. bins=R_2R.Param.bins;
  7. binint=R_2R.Param.binint;
  8. binstart=R_2R.Param.binstart;
  9. PStatBins=0.01; %using more stringent cutoff to reduce pre-delivery noise
  10. %divide neurons up by region
  11. NAneurons=strcmp(R_2R.Ninfo(:,3),'NA');
  12. VPneurons=strcmp(R_2R.Ninfo(:,3),'VP');
  13. %which bins bound the area examined for reward-selectivity? (in seconds)
  14. Time1=0.4; %seconds
  15. Time2=3; %seconds
  16. Bin1=(((Time1-BinDura(2)/2)-binstart)/binint); %convert to bin name
  17. Bin2=(((Time2-BinDura(2)/2)-binstart)/binint); %convert to bin name
  18. %sorting bin -- which bin the neurons' activity is sorted on for heatmap(in seconds)
  19. SortBinTime=1.1; %seconds
  20. SortBin=round((((SortBinTime-BinDura(2)/2)-binstart)/binint)); %convert to bin name
  21. sucrose=[1 0.6 0.1];
  22. maltodextrin=[.9 0.3 .9];
  23. water=[0.00 0.75 0.75];
  24. total=[0.3 0.1 0.8];
  25. exc=[0 113/255 188/255];
  26. inh=[240/255 0 50/255];
  27. %% bins analysis
  28. %first and last bin aren't included because you can't compare to the previous/subsequent bin
  29. %this axis plots the bins on their centers
  30. xaxis=linspace(binstart+binint+BinDura(2)/2,binstart+(bins-2)*binint+BinDura(2)/2,bins-2);
  31. for i=2:(bins-1) %no including first or last bin because can't compare to previous/subsequent bin
  32. %finds out whether firing is stronger (high excitation or lower inhibition) for 1 or 2
  33. for k=1:length(R_2R.Ninfo) %runs through neurons
  34. if R_2R.BinStatRwrd{i,1}(k).IntSig < PStatBins %if neuron is significant for this bin
  35. if R_2R.BinStatRwrd{i-1,1}(k).IntSig < PStatBins || R_2R.BinStatRwrd{i+1,1}(k).IntSig < PStatBins %either previous or subsequent bin must be significant
  36. if R_2R.BinStatRwrd{i,1}(k).R1Mean > R_2R.BinStatRwrd{i,1}(k).R2Mean %if firing is greater on sucrose trials than maltodextrin
  37. R_2R.BinRewPref{i,1}(k,1)=1;
  38. else
  39. R_2R.BinRewPref{i,1}(k,1)=2; %otherwise maltodextrin must be greater than sucrose
  40. end
  41. else
  42. R_2R.BinRewPref{i,1}(k,1)=0; %if not significant in 2 consecutive bins
  43. end
  44. else
  45. R_2R.BinRewPref{i,1}(k,1)=0; %if no sig reward modulation
  46. end
  47. end
  48. %find how many NAc neurons have significant reward modulation in each bin
  49. NN1perBin(i,1)=sum(R_2R.BinRewPref{i,1}(NAneurons,1)==1); %sucrose pref
  50. NN2perBin(i,1)=sum(R_2R.BinRewPref{i,1}(NAneurons,1)==2); %malto pref
  51. NNperBin(i,1)=sum(R_2R.BinRewPref{i,1}(NAneurons,1)>0); %either
  52. %normalize to number of neurons in population
  53. NN1norm=NN1perBin./sum(NAneurons);
  54. NN2norm=NN2perBin./sum(NAneurons);
  55. NNnorm=NNperBin./sum(NAneurons);
  56. %find how many VP neurons have significant reward modulation in each bin
  57. NV1perBin(i,1)=sum(R_2R.BinRewPref{i,1}(VPneurons,1)==1); %sucrose pref
  58. NV2perBin(i,1)=sum(R_2R.BinRewPref{i,1}(VPneurons,1)==2); %malto pref
  59. NVperBin(i,1)=sum(R_2R.BinRewPref{i,1}(VPneurons,1)>0); %either
  60. %normalize to number of neurons in population
  61. NV1norm=NV1perBin./sum(VPneurons);
  62. NV2norm=NV2perBin./sum(VPneurons);
  63. NVnorm=NVperBin./sum(VPneurons);
  64. end
  65. %Cumulative reward selectivity
  66. cumsel=zeros(length(R_2R.Ninfo),bins); %set up result matrix
  67. cumsel1=zeros(length(R_2R.Ninfo),bins); %set up result matrix for sucrose
  68. cumsel2=zeros(length(R_2R.Ninfo),bins); %set up result matrix for maltodextrin
  69. %note, this has to be corrected to +1 because of the way the bin matrix is
  70. %layed out (bin 0 is the first column, not the 0th column)
  71. for i=1:length(R_2R.Ninfo) %go through each neuron
  72. for j=2:bins-1 %look in each bin we did analysis on
  73. if R_2R.BinRewPref{j,1}(i,1)>0 || cumsel(i,j-1)==1
  74. cumsel(i,j) = 1;
  75. end
  76. if R_2R.BinRewPref{j,1}(i,1)==1 || cumsel1(i,j-1)==1
  77. cumsel1(i,j) = 1;
  78. end
  79. if R_2R.BinRewPref{j,1}(i,1)==2 || cumsel2(i,j-1)==1
  80. cumsel2(i,j) = 1;
  81. end
  82. end
  83. end
  84. %plotting number of significantly modulated neurons across time
  85. %NAc
  86. subplot(2,3,1);
  87. hold on;
  88. plot(xaxis,NNnorm(2:bins-1),'Color', total,'linewidth',1.5);
  89. plot(xaxis,NN1norm(2:bins-1),'Color',sucrose,'linewidth',1.5);
  90. plot(xaxis,NN2norm(2:bins-1),'Color',maltodextrin,'linewidth',1.5);
  91. plot([Time1 Time1],[-1 1],':','color','k','linewidth',0.75);
  92. plot([Time2 Time2],[-1 1],':','color','k','linewidth',0.75);
  93. axis([xaxis(1) xaxis(end) 0 0.4]);
  94. legend('Total','Suc > mal','Mal > suc','Location','northeast')
  95. ylabel('Fraction of population');
  96. title('NAc reward-selective neurons');
  97. %VP
  98. subplot(2,3,2);
  99. hold on;
  100. plot(xaxis,NVnorm(2:bins-1),'Color', total,'linewidth',1.5);
  101. plot(xaxis,NV1norm(2:bins-1),'Color',sucrose,'linewidth',1.5);
  102. plot(xaxis,NV2norm(2:bins-1),'Color',maltodextrin,'linewidth',1.5);
  103. plot([Time1 Time1],[-1 1],':','color','k','linewidth',0.75);
  104. plot([Time2 Time2],[-1 1],':','color','k','linewidth',0.75);
  105. axis([xaxis(1) xaxis(end) 0 0.4]);
  106. legend('Total','Suc > mal','Mal > suc','Location','northeast')
  107. ylabel('Fraction of population');
  108. title('VP reward-selective neurons');
  109. %plotting cumulative selectivity in each region
  110. %NAc
  111. subplot(2,3,4);
  112. hold on;
  113. plot(xaxis,sum(cumsel(NAneurons,2:bins-1),1)/sum(NAneurons),'Color', total,'linewidth',1.5);
  114. plot(xaxis,sum(cumsel1(NAneurons,2:bins-1),1)/sum(NAneurons),'Color', sucrose,'linewidth',1.5);
  115. plot(xaxis,sum(cumsel2(NAneurons,2:bins-1),1)/sum(NAneurons),'Color', maltodextrin,'linewidth',1.5);
  116. plot([Time1 Time1],[0 1],':','color','k','linewidth',0.75);
  117. plot([Time2 Time2],[0 1],':','color','k','linewidth',0.75);
  118. axis([xaxis(1) xaxis(end) 0 0.75]);
  119. xlabel('Seconds from reward delivery');
  120. ylabel('Cumulative fraction');
  121. %VP
  122. subplot(2,3,5);
  123. hold on;
  124. plot(xaxis,sum(cumsel(VPneurons,2:bins-1),1)/sum(VPneurons),'Color', total,'linewidth',1.5);
  125. plot(xaxis,sum(cumsel1(VPneurons,2:bins-1),1)/sum(VPneurons),'Color', sucrose,'linewidth',1.5);
  126. plot(xaxis,sum(cumsel2(VPneurons,2:bins-1),1)/sum(VPneurons),'Color', maltodextrin,'linewidth',1.5);
  127. plot([Time1 Time1],[0 1],':','color','k','linewidth',0.75);
  128. plot([Time2 Time2],[0 1],':','color','k','linewidth',0.75);
  129. axis([xaxis(1) xaxis(end) 0 0.75]);
  130. xlabel('Seconds from RD');
  131. ylabel('Cumulative fraction');
  132. %plot difference between the two regions for each measure
  133. %reward selective neurons per bin
  134. subplot(2,3,3);
  135. hold on;
  136. plot(xaxis,NNnorm(2:bins-1)-NVnorm(2:bins-1),'Color', total,'linewidth',1.5);
  137. plot(xaxis,NN1norm(2:bins-1)-NV1norm(2:bins-1),'Color',sucrose,'linewidth',1.5);
  138. plot(xaxis,NN2norm(2:bins-1)-NV2norm(2:bins-1),'Color',maltodextrin,'linewidth',1.5);
  139. axis([xaxis(1) xaxis(end) -0.3 0.3]);
  140. plot([xaxis(1) xaxis(end)],[0 0],'color','k','linewidth',0.75);
  141. plot([Time1 Time1],[-1 1],':','color','k','linewidth',0.75);
  142. plot([Time2 Time2],[-1 1],':','color','k','linewidth',0.75);
  143. legend('Total','Suc > mal','Mal > suc','Location','northeast')
  144. title('Difference (NAc - VP)');
  145. ylabel('Fraction of population');
  146. %cumulative selectivity
  147. subplot(2,3,6);
  148. hold on;
  149. plot(xaxis,sum(cumsel(NAneurons,2:bins-1),1)/sum(NAneurons)-sum(cumsel(VPneurons,2:bins-1),1)/sum(VPneurons),'Color', total,'linewidth',1.5);
  150. plot(xaxis,sum(cumsel1(NAneurons,2:bins-1),1)/sum(NAneurons)-sum(cumsel1(VPneurons,2:bins-1),1)/sum(VPneurons),'Color', sucrose,'linewidth',1.5);
  151. plot(xaxis,sum(cumsel2(NAneurons,2:bins-1),1)/sum(NAneurons)-sum(cumsel2(VPneurons,2:bins-1),1)/sum(VPneurons),'Color', maltodextrin,'linewidth',1.5);
  152. plot([Time1 Time1],[-1 1],':','color','k','linewidth',0.75);
  153. plot([Time2 Time2],[-1 1],':','color','k','linewidth',0.75);
  154. axis([xaxis(1) xaxis(end) -Time1 Time1]);
  155. plot([xaxis(1) xaxis(end)],[0 0],'color','k','linewidth',0.75);
  156. xlabel('Seconds from RD');
  157. ylabel('Cumulative fraction');
  158. %% individual rat data
  159. figure;
  160. %split data up into individual rats
  161. for i=1:length(R_2R.Ninfo)
  162. A=char(R_2R.Ninfo(i,4));
  163. Rats(i,:)=cellstr(A);
  164. end
  165. C=unique(Rats);
  166. for i=1:length(C)
  167. Sel=strcmp(C(i),Rats);
  168. for j=2:bins-1
  169. NRat1(j,1)=sum(R_2R.BinRewPref{j,1}(Sel,1)==1)/sum(Sel);
  170. NRat2(j,1)=sum(R_2R.BinRewPref{j,1}(Sel,1)==2)/sum(Sel);
  171. NRat(j,1)=sum(R_2R.BinRewPref{j,1}(Sel,1)>0)/sum(Sel);
  172. end
  173. %graphing
  174. subplot(4,3,i);
  175. hold on;
  176. plot(xaxis,NRat(2:bins-1),'Color', total,'linewidth',1.5);
  177. plot(xaxis,NRat1(2:65),'Color',sucrose,'linewidth',1.5);
  178. plot(xaxis,NRat2(2:65),'Color',maltodextrin,'linewidth',1.5);
  179. xlabel('Seconds from reward delivery');
  180. title([cell2mat(C(i)) ' (n=' num2str(sum(Sel)) ')'])
  181. axis([xaxis(1) xaxis(end) 0 0.5]);
  182. legend('Total neurons','Suc > mal Hz','Mal > suc Hz','Location','northeast')
  183. ylabel('Fraction of total population');
  184. end
  185. %% plotting sucrose-selective neurons
  186. figure;
  187. %color map
  188. [magma,inferno,plasma,viridis]=colormaps;
  189. colormap(plasma);
  190. c=[-100 2000];ClimE=sign(c).*abs(c).^(1/4);%colormap
  191. %events we're looking at
  192. ev1=strcmp('RD1', R_2R.Erefnames);
  193. ev2=strcmp('RD2', R_2R.Erefnames);
  194. %setting up parameters
  195. Xaxis=[-2 5];
  196. inttime=find(R_2R.Param.Tm>=Xaxis(1) & R_2R.Param.Tm<=Xaxis(2));
  197. paramtime=R_2R.Param.Tm(inttime);
  198. %find all neurons with greater firing for sucrose
  199. for i = 1:(Bin2-Bin1+1)
  200. %the added +1 is necessary because bin 20 is the 21st entry in the matrix
  201. Pref1(:,i)=R_2R.BinRewPref{Bin1+i}==1; %get neurons that have greater firing for sucrose in any of the bins bounded above
  202. Resp11(:,i)=Pref1(:,i)&cat(1,R_2R.BinStatRwrd{Bin1+i,1}.SucRespDir)==1; %get neurons with excitation to sucrose
  203. Resp12(:,i)=Pref1(:,i)&cat(1,R_2R.BinStatRwrd{Bin1+i,1}.MalRespDir)==-1;%get neurons with inhibition to maltodextrin
  204. end
  205. Sel=sum(Pref1,2)>0; %all neurons selective for sucrose in any bin
  206. Sel2=sum(Resp11,2)>0; %all selective neurons sucrose excited in any bin
  207. Sel3=sum(Resp12,2)>0; %all selective neurons malto inhibited in any bin
  208. %-----------------NAc--------------------------------------------
  209. subplot(4,40,[15:23]); %heatmap of sucrose preferring neurons' response to sucrose
  210. Neurons=R_2R.Ev(ev1).PSTHz(Sel&NAneurons,inttime); %get the firing rates of neurons of interest
  211. SucResp=cat(1,R_2R.BinStatRwrd{SortBin+1,1}.R1Mean); %sucrose responses
  212. TMP=SucResp(Sel&NAneurons); %find the magnitude of the excitations for sucrose for this bin
  213. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  214. [~,SORTimg]=sort(TMP);
  215. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  216. imagesc(paramtime,[1,sum(Sel&NAneurons,1)],Neurons,ClimE);
  217. title(['Sucrose trials']);
  218. ylabel('Individual neurons');
  219. hold on;
  220. plot([0 0],[0 sum(Sel&NAneurons)],':','color','k','linewidth',0.75);
  221. subplot(4,40,[27:35]); %heatmap of sucrose preferring neurons' response to maltodextrin
  222. Neurons=R_2R.Ev(ev2).PSTHz(Sel&NAneurons,inttime); %get the firing rates of neurons of interest
  223. Neurons=Neurons(SORTimg,:); %sort the neurons same as before
  224. imagesc(paramtime,[1,sum(Sel&NAneurons,1)],Neurons,ClimE);
  225. title(['Maltodextrin trials']);
  226. hold on;
  227. plot([0 0],[0 sum(Sel&NAneurons)],':','color','k','linewidth',0.75);
  228. %plot sucrose preferring neurons to sucrose
  229. psth1=nanmean(R_2R.Ev(ev1).PSTHz(Sel&NAneurons,inttime),1);
  230. sem1=nanste(R_2R.Ev(ev1).PSTHz(Sel&NAneurons,inttime),1); %calculate standard error of the mean
  231. up1=psth1+sem1;
  232. down1=psth1-sem1;
  233. %plot sucrose preferring neurons to malt
  234. psth2=nanmean(R_2R.Ev(ev2).PSTHz(Sel&NAneurons,inttime),1);
  235. sem2=nanste(R_2R.Ev(ev2).PSTHz(Sel&NAneurons,inttime),1); %calculate standard error of the mean
  236. up2=psth2+sem2;
  237. down2=psth2-sem2;
  238. %plotting
  239. subplot(4,3,1);
  240. title(['Suc>mal (n=' num2str(sum(Sel&NAneurons)) ' of ' num2str(sum(NAneurons)) ')'])
  241. hold on;
  242. plot(paramtime,psth1,'Color',sucrose,'linewidth',1);
  243. plot(paramtime,psth2,'Color',maltodextrin,'linewidth',1);
  244. patch([paramtime,paramtime(end:-1:1)],[up1,down1(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  245. patch([paramtime,paramtime(end:-1:1)],[up2,down2(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  246. plot([-2 5],[0 0],':','color','k','linewidth',0.75);
  247. plot([0 0],[-1 10],':','color','k','linewidth',0.75);
  248. axis([-2 5 -1 4]);
  249. ylabel('Mean firing (z-score)');
  250. legend('Suc trials','Mal trials');
  251. %display inhibitions and excitations
  252. both = sum(Sel2&Sel3&NAneurons);
  253. excite = sum(Sel2&NAneurons)-both;
  254. inhib = sum(Sel3&NAneurons)-both;
  255. subplot(4,40,40);
  256. b = bar([inhib both excite; 0 0 0],'stacked');
  257. b(1,1).FaceColor=maltodextrin;
  258. b(1,2).FaceColor=total;
  259. b(1,3).FaceColor=sucrose;
  260. axis([1 1.2 0 both+excite+inhib]);
  261. ylabel('Inh / Both / Excited');
  262. set(gca,'xtick',[])
  263. %----------------VP----------------
  264. subplot(4,40,[80+15:80+23]); %heatmap of sucrose preferring neurons' response to sucrose
  265. Neurons=R_2R.Ev(ev1).PSTHz(Sel&VPneurons,inttime); %get the firing rates of neurons of interest
  266. SucResp=cat(1,R_2R.BinStatRwrd{SortBin+1,1}.R1Mean); %sucrose responses
  267. TMP=SucResp(Sel&VPneurons); %find the magnitude of the excitations for sucrose for this bin
  268. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  269. [~,SORTimg]=sort(TMP);
  270. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  271. imagesc(paramtime,[1,sum(Sel&VPneurons,1)],Neurons,ClimE);
  272. title(['Sucrose trials']);
  273. ylabel('Individual neurons');
  274. hold on;
  275. plot([0 0],[0 sum(Sel&VPneurons)],':','color','k','linewidth',0.75);
  276. subplot(4,40,[80+27:80+35]); %heatmap of sucrose preferring neurons' response to maltodextrin
  277. Neurons=R_2R.Ev(ev2).PSTHz(Sel&VPneurons,inttime); %get the firing rates of neurons of interest
  278. Neurons=Neurons(SORTimg,:); %sort the neurons same as before
  279. imagesc(paramtime,[1,sum(Sel&VPneurons,1)],Neurons,ClimE);
  280. title(['Maltodextrin trials']);
  281. hold on;
  282. plot([0 0],[0 sum(Sel&VPneurons)],':','color','k','linewidth',0.75);
  283. %plot sucrose preferring neurons to sucrose
  284. psth1=nanmean(R_2R.Ev(ev1).PSTHz(Sel&VPneurons,inttime),1);
  285. sem1=nanste(R_2R.Ev(ev1).PSTHz(Sel&VPneurons,inttime),1); %calculate standard error of the mean
  286. up1=psth1+sem1;
  287. down1=psth1-sem1;
  288. %plot sucrose preferring neurons to malt
  289. psth2=nanmean(R_2R.Ev(ev2).PSTHz(Sel&VPneurons,inttime),1);
  290. sem2=nanste(R_2R.Ev(ev2).PSTHz(Sel&VPneurons,inttime),1); %calculate standard error of the mean
  291. up2=psth2+sem2;
  292. down2=psth2-sem2;
  293. %plotting
  294. subplot(4,3,7);
  295. title(['Suc>mal (n=' num2str(sum(Sel&VPneurons)) ' of ' num2str(sum(VPneurons)) ')'])
  296. hold on;
  297. plot(paramtime,psth1,'Color',sucrose,'linewidth',1);
  298. plot(paramtime,psth2,'Color',maltodextrin,'linewidth',1);
  299. patch([paramtime,paramtime(end:-1:1)],[up1,down1(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  300. patch([paramtime,paramtime(end:-1:1)],[up2,down2(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  301. plot([-2 5],[0 0],':','color','k','linewidth',0.75);
  302. plot([0 0],[-1 10],':','color','k','linewidth',0.75);
  303. axis([-2 5 -0.6 4]);
  304. ylabel('Mean firing (z-score)');
  305. legend('Suc trials','Mal trials');
  306. %display inhibitions and excitations
  307. both = sum(Sel2&Sel3&VPneurons);
  308. excite = sum(Sel2&VPneurons)-both;
  309. inhib = sum(Sel3&VPneurons)-both;
  310. subplot(4,40,120);
  311. b = bar([inhib both excite; 0 0 0],'stacked');
  312. b(1,1).FaceColor=maltodextrin;
  313. b(1,2).FaceColor=total;
  314. b(1,3).FaceColor=sucrose;
  315. axis([1 1.2 0 both+excite+inhib]);
  316. ylabel('Inh / Both / Excited');
  317. set(gca,'xtick',[])
  318. %% plotting maltodextrin-selective neurons
  319. %find all neurons with greater firing for maltodextrin
  320. for i = 1:(Bin2-Bin1+1)
  321. %the added +1 is necessary because bin 20 is the 21st entry in the matrix
  322. Pref2(:,i)=R_2R.BinRewPref{Bin1+i}==2; %get neurons that have greater firing for maltodextrin in any of the bins bounded above
  323. Resp21(:,i)=Pref2(:,i)&cat(1,R_2R.BinStatRwrd{Bin1+i,1}.SucRespDir)==-1; %get neurons with inhibition to sucrose
  324. Resp22(:,i)=Pref2(:,i)&cat(1,R_2R.BinStatRwrd{Bin1+i,1}.MalRespDir)==1;%get neurons with excitation to maltodextrin
  325. end
  326. Mel=sum(Pref2,2)>0; %all neurons selective for malotdextrin in any bin
  327. Mel2=sum(Resp21,2)>0; %all selective neurons sucrose inhibited in any bin
  328. Mel3=sum(Resp22,2)>0; %all selective neurons malto excited in any bin
  329. %-----------------NAc--------------------------------------------
  330. subplot(4,40,[40+15:40+23]); %heatmap of maltodextrin preferring neurons' response to sucrose
  331. Neurons=R_2R.Ev(ev1).PSTHz(Mel&NAneurons,inttime); %get the firing rates of neurons of interest
  332. MalResp=cat(1,R_2R.BinStatRwrd{SortBin+1,1}.R2Mean); %sucrose responses
  333. TMP=MalResp(Mel&NAneurons); %find the magnitude of the excitations for sucrose for this bin
  334. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  335. [~,SORTimg]=sort(TMP);
  336. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  337. imagesc(paramtime,[1,sum(Mel&NAneurons,1)],Neurons,ClimE);
  338. title(['Sucrose trials']);
  339. xlabel('Seconds from RD');
  340. ylabel('Individual neurons');
  341. hold on;
  342. plot([0 0],[0 sum(Mel&NAneurons)],':','color','k','linewidth',0.75);
  343. subplot(4,40,[40+27:40+35]); %heatmap of maltodextrin preferring neurons' response to maltodextrin
  344. Neurons=R_2R.Ev(ev2).PSTHz(Mel&NAneurons,inttime); %get the firing rates of neurons of interest
  345. Neurons=Neurons(SORTimg,:); %sort the neurons same as before
  346. imagesc(paramtime,[1,sum(Mel&NAneurons,1)],Neurons,ClimE);
  347. title(['Maltodextrin trials']);
  348. xlabel('Seconds from RD');
  349. hold on;
  350. plot([0 0],[0 sum(Mel&NAneurons)],':','color','k','linewidth',0.75);
  351. %plot sucrose preferring neurons to sucrose
  352. psth1=nanmean(R_2R.Ev(ev1).PSTHz(Mel&NAneurons,inttime),1);
  353. sem1=nanste(R_2R.Ev(ev1).PSTHz(Mel&NAneurons,inttime),1); %calculate standard error of the mean
  354. up1=psth1+sem1;
  355. down1=psth1-sem1;
  356. %plot sucrose preferring neurons to malt
  357. psth2=nanmean(R_2R.Ev(ev2).PSTHz(Mel&NAneurons,inttime),1);
  358. sem2=nanste(R_2R.Ev(ev2).PSTHz(Mel&NAneurons,inttime),1); %calculate standard error of the mean
  359. up2=psth2+sem2;
  360. down2=psth2-sem2;
  361. %plotting
  362. subplot(4,3,4);
  363. title(['Mal>suc (n=' num2str(sum(Mel&NAneurons)) ' of ' num2str(sum(NAneurons)) ')'])
  364. hold on;
  365. plot(paramtime,psth1,'Color',sucrose,'linewidth',1);
  366. plot(paramtime,psth2,'Color',maltodextrin,'linewidth',1);
  367. patch([paramtime,paramtime(end:-1:1)],[up1,down1(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  368. patch([paramtime,paramtime(end:-1:1)],[up2,down2(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  369. plot([-2 5],[0 0],':','color','k','linewidth',0.75);
  370. plot([0 0],[-2 7],':','color','k','linewidth',0.75);
  371. axis([-2 5 -1.2 3]);
  372. ylabel('Mean firing (z-score)');
  373. xlabel('Seconds from RD');
  374. legend('Suc trials','Mal trials','Location','northeast');
  375. %display inhibitions and excitations
  376. both = sum(Mel2&Mel3&NAneurons);
  377. excite = sum(Mel3&NAneurons)-both;
  378. inhib = sum(Mel2&NAneurons)-both;
  379. subplot(4,40,80);
  380. b = bar([inhib both excite; 0 0 0],'stacked');
  381. b(1,1).FaceColor=sucrose;
  382. b(1,2).FaceColor=total;
  383. b(1,3).FaceColor=maltodextrin;
  384. axis([1 1.2 0 both+excite+inhib]);
  385. ylabel('Inh / Both / Excited');
  386. set(gca,'xtick',[]);
  387. %----------------VP----------------
  388. subplot(4,40,[120+15:120+23]); %heatmap of maltodextrin preferring neurons' response to sucrose
  389. Neurons=R_2R.Ev(ev1).PSTHz(Mel&VPneurons,inttime); %get the firing rates of neurons of interest
  390. MalResp=cat(1,R_2R.BinStatRwrd{SortBin+1,1}.R2Mean); %sucrose responses
  391. TMP=MalResp(Mel&VPneurons); %find the magnitude of the excitations for sucrose for this bin
  392. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  393. [~,SORTimg]=sort(TMP);
  394. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  395. imagesc(paramtime,[1,sum(Mel&VPneurons,1)],Neurons,ClimE);
  396. title(['Sucrose trials']);
  397. xlabel('Seconds from RD');
  398. ylabel('Individual neurons');
  399. hold on;
  400. plot([0 0],[0 sum(Mel&VPneurons)],':','color','k','linewidth',0.75);
  401. subplot(4,40,[120+27:120+35]); %heatmap of maltodextrin preferring neurons' response to maltodextrin
  402. Neurons=R_2R.Ev(ev2).PSTHz(Mel&VPneurons,inttime); %get the firing rates of neurons of interest
  403. Neurons=Neurons(SORTimg,:); %sort the neurons same as before
  404. imagesc(paramtime,[1,sum(Mel&VPneurons,1)],Neurons,ClimE);
  405. title(['Maltodextrin trials']);
  406. xlabel('Seconds from RD');
  407. hold on;
  408. plot([0 0],[0 sum(Mel&VPneurons)],':','color','k','linewidth',0.75);
  409. %plot maltodextrin preferring neurons to sucrose
  410. psth1=nanmean(R_2R.Ev(ev1).PSTHz(Mel&VPneurons,inttime),1);
  411. sem1=nanste(R_2R.Ev(ev1).PSTHz(Mel&VPneurons,inttime),1); %calculate standard error of the mean
  412. up1=psth1+sem1;
  413. down1=psth1-sem1;
  414. %plot malt preferring neurons to malt
  415. psth2=nanmean(R_2R.Ev(ev2).PSTHz(Mel&VPneurons,inttime),1);
  416. sem2=nanste(R_2R.Ev(ev2).PSTHz(Mel&VPneurons,inttime),1); %calculate standard error of the mean
  417. up2=psth2+sem2;
  418. down2=psth2-sem2;
  419. %plotting
  420. subplot(4,3,10);
  421. title(['Mal>suc (n=' num2str(sum(Mel&VPneurons)) ' of ' num2str(sum(VPneurons)) ')'])
  422. hold on;
  423. plot(paramtime,psth1,'Color',sucrose,'linewidth',1);
  424. plot(paramtime,psth2,'Color',maltodextrin,'linewidth',1);
  425. patch([paramtime,paramtime(end:-1:1)],[up1,down1(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  426. patch([paramtime,paramtime(end:-1:1)],[up2,down2(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  427. plot([-2 5],[0 0],':','color','k','linewidth',0.75);
  428. plot([0 0],[-2 7],':','color','k','linewidth',0.75);
  429. axis([-2 5 -1.5 2.5]);
  430. ylabel('Mean firing (z-score)');
  431. xlabel('Seconds from RD');
  432. legend('Suc trials','Mal trials','Location','northeast');
  433. %display inhibitions and excitations
  434. both = sum(Mel2&Mel3&VPneurons);
  435. excite = sum(Mel3&VPneurons)-both;
  436. inhib = sum(Mel2&VPneurons)-both;
  437. subplot(4,40,160);
  438. b = bar([inhib both excite; 0 0 0],'stacked');
  439. b(1,1).FaceColor=sucrose;
  440. b(1,2).FaceColor=total;
  441. b(1,3).FaceColor=maltodextrin;
  442. axis([1 1.2 0 both+excite+inhib]);
  443. ylabel('Inh / Both / Excited');
  444. set(gca,'xtick',[]);
  445. %% creating and saving new variables
  446. R_2R.RSinfo=R_2R.Ninfo(Sel|Mel,1:2); %reward-selective neurons
  447. R_2R.RNSinfo=R_2R.Ninfo(Sel==0 & Mel==0,1:2); %reward-nonselective neurons
  448. R_2R.SucN=Sel;
  449. R_2R.MalN=Mel;
  450. % proportion summary and chi squared test for reward selective neurons
  451. R_2R.RegSelX2(1,1)=sum((Sel | Mel) & NAneurons)/sum(NAneurons); %how many selective NAc neurons
  452. R_2R.RegSelX2(1,2)=sum((Sel | Mel) & VPneurons)/sum(VPneurons); %how many selective VP neurons
  453. [~,R_2R.RegSelX2(2,1),R_2R.RegSelX2(2,2)]=crosstab(Sel | Mel,NAneurons);
  454. % proportion summary and chi squared test for max neurons in any bin
  455. R_2R.RegMaxSelX2(1,1)=max(NNnorm); %how many selective NAc neurons
  456. R_2R.RegMaxSelX2(1,2)=max(NVnorm); %how many selective VP neurons
  457. [~,R_2R.RegMaxSelX2(2,1),R_2R.RegMaxSelX2(2,2)]=crosstab(cat(1,ones(max(NNperBin),1),zeros(sum(NAneurons)-max(NNperBin),1),ones(max(NVperBin),1),zeros(sum(VPneurons)-max(NVperBin),1)),NAneurons);
  458. save('R_2R.mat','R_2R');
  459. %divide neurons up by region
  460. NAneurons=strcmp(R_2R.Ninfo(:,3),'NA');
  461. VPneurons=strcmp(R_2R.Ninfo(:,3),'VP');
  462. Xaxis=[-1 2];
  463. Ishow=find(R_2R.Param.Tm>=Xaxis(1) & R_2R.Param.Tm<=Xaxis(2));
  464. time1=R_2R.Param.Tm(Ishow);
  465. Xaxis2=[-2 2];
  466. Ushow=find(R_2R.Param.Tm>=Xaxis2(1) & R_2R.Param.Tm<=Xaxis2(2));
  467. time2=R_2R.Param.Tm(Ushow);
  468. inh=[0.1 0.021154 0.6];
  469. exc=[0.9 0.75 0.205816];
  470. Cue=strcmp('Cue', R_2R.Erefnames);
  471. PE=strcmp('PECue', R_2R.Erefnames);
  472. RD=strcmp('RD', R_2R.Erefnames); %should this be LickR or RD?
  473. %% Plotting heatmaps of all neurons to each event
  474. figure;
  475. %color map
  476. [magma,inferno,plasma,viridis]=colormaps;
  477. colormap(plasma);
  478. c=[-100 2000];ClimE=sign(c).*abs(c).^(1/4);%colormap
  479. for i=1:2
  480. if i==1 Reg=NAneurons; end %1 is NAc
  481. if i==2 Reg=VPneurons; end %2 is VP
  482. Sel=Reg&R_2R.Ev(Cue).RespDir<2; %gets all neurons
  483. %sort cue heatmap by magnitude of response
  484. Neurons=R_2R.Ev(Cue).PSTHz(Sel,Ishow); %get the firing rates of neurons of interest
  485. TMP=R_2R.Ev(Cue).Meanz(Sel); %find the magnitude of the inhibitions for this event
  486. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  487. [~,SORTimg]=sort(TMP);
  488. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  489. %heatmap
  490. subplot(4,6,[1 7]+(i-1)*12);
  491. imagesc(time1,[1,sum(Sel,1)],Neurons,ClimE); title('Cue responses');
  492. xlabel('Seconds post cue');
  493. ylabel('Individual neurons sorted by response strength');
  494. hold on;
  495. plot([0 0],[0 sum(Sel)],':','color','k','linewidth',0.75);
  496. %sort PE heatmap by magnitude of response
  497. Neurons=R_2R.Ev(PE).PSTHz(Sel,Ushow); %get the firing rates of neurons of interest
  498. TMP=R_2R.Ev(PE).Meanz(Sel); %find the magnitude of the inhibitions for this event
  499. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  500. [~,SORTimg]=sort(TMP);
  501. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  502. %heatmap
  503. subplot(4,6,[3 9]+(i-1)*12);
  504. imagesc(time2,[1,sum(Sel,1)],Neurons,ClimE); title('PE responses');
  505. xlabel('Seconds post PE');
  506. hold on;
  507. plot([0 0],[0 sum(Sel)],':','color','k','linewidth',0.75);
  508. %sort RD heatmap by magnitude of response
  509. Neurons=R_2R.Ev(RD).PSTHz(Sel,Ushow); %get the firing rates of neurons of interest
  510. TMP=R_2R.Ev(RD).Meanz(Sel); %find the magnitude of the inhibitions for this event
  511. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  512. [~,SORTimg]=sort(TMP);
  513. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  514. %heatmap
  515. subplot(4,6,[5 11]+(i-1)*12);
  516. imagesc(time2,[1,sum(Sel,1)],Neurons,ClimE); title('Reward responses');
  517. xlabel('Seconds post RD');
  518. hold on;
  519. plot([0 0],[0 sum(Sel)],':','color','k','linewidth',0.75);
  520. %% Plotting neurons that respond to the cue
  521. %inhibitions
  522. Sel=Reg&R_2R.Ev(Cue).RespDir<0; %Find neurons that have an inhibitory response to this event
  523. %average firing rate
  524. subplot(4,6,2+(i-1)*12);
  525. psthI=nanmean(R_2R.Ev(Cue).PSTHz(Sel,Ishow),1); %find the average firing rate of the neurons at the time of the event
  526. semI=nanste(R_2R.Ev(Cue).PSTHz(Sel,Ishow),1); %calculate standard error of the mean
  527. upI=psthI+semI;
  528. downI=psthI-semI;
  529. hold on;
  530. patch([time1,time1(end:-1:1)],[upI,downI(end:-1:1)],inh,'EdgeColor','none');alpha(0.5);
  531. plot(time1,psthI,'Color',inh,'linewidth',1); title('Mean firing (z-score)'); %create plot of avg firing rate
  532. plot([-1 2],[0 0],':','color','k','linewidth',0.75);
  533. plot([0 0],[-3 9],':','color','k','linewidth',0.75);
  534. axis([-1 2 min(downI)-0.2 max(upI)+0.2]);
  535. title(['Cue inhibitions (' num2str(round(100*sum(Sel)/sum(Reg))) '%)'])
  536. ylabel('Z-score');
  537. %excitation
  538. Sel=Reg&R_2R.Ev(Cue).RespDir>0; %Find neurons that have an excitatory response to this event
  539. %average firing rate
  540. subplot(4,6,8+(i-1)*12);
  541. psthE=nanmean(R_2R.Ev(Cue).PSTHz(Sel,Ishow),1);
  542. semE=nanste(R_2R.Ev(Cue).PSTHz(Sel,Ishow),1); %calculate standard error of the mean
  543. upE=psthE+semE;
  544. downE=psthE-semE;
  545. hold on;
  546. patch([time1,time1(end:-1:1)],[upE,downE(end:-1:1)],exc,'EdgeColor','none');alpha(0.5);
  547. plot(time1,psthE,'Color',exc,'linewidth',1);
  548. plot([-1 2],[0 0],':','color','k','linewidth',0.75);
  549. plot([0 0],[-3 9],':','color','k','linewidth',0.75);
  550. axis([-1 2 min(downE)-0.2 max(upE)+0.3]);
  551. title(['Cue excitations (' num2str(round(100*sum(Sel)/sum(Reg))) '%)'])
  552. ylabel('Z-score');
  553. %% Plotting neurons that respond to PE
  554. %inhibitions
  555. Sel=Reg&R_2R.Ev(PE).RespDir<0; %Find neurons that have an inhibitory response to this event
  556. %average firing rate
  557. subplot(4,6,4+(i-1)*12);
  558. psthI=nanmean(R_2R.Ev(PE).PSTHz(Sel,Ushow),1); %find the average firing rate of the neurons at the time of the event
  559. semI=nanste(R_2R.Ev(PE).PSTHz(Sel,Ushow),1); %calculate standard error of the mean
  560. upI=psthI+semI;
  561. downI=psthI-semI;
  562. hold on;
  563. patch([time2,time2(end:-1:1)],[upI,downI(end:-1:1)],inh,'EdgeColor','none');alpha(0.5);
  564. plot(time2,psthI,'Color',inh,'linewidth',1); title('Mean firing (z-score)'); %create plot of avg firing rate
  565. plot([-2 2],[0 0],':','color','k','linewidth',0.75);
  566. plot([0 0],[-3 9],':','color','k','linewidth',0.75);
  567. axis([-2 2 min(downI)-0.2 max(upI)+0.2]);
  568. title(['PE inhibitions (' num2str(round(100*sum(Sel)/sum(Reg))) '%)'])
  569. ylabel('Z-score');
  570. %excitation
  571. Sel=Reg&R_2R.Ev(PE).RespDir>0; %Find neurons that have an excitatory response to this event
  572. %average firing rate
  573. subplot(4,6,10+(i-1)*12);
  574. psthE=nanmean(R_2R.Ev(PE).PSTHz(Sel,Ushow),1);
  575. semE=nanste(R_2R.Ev(PE).PSTHz(Sel,Ushow),1); %calculate standard error of the mean
  576. upE=psthE+semE;
  577. downE=psthE-semE;
  578. hold on;
  579. patch([time2,time2(end:-1:1)],[upE,downE(end:-1:1)],exc,'EdgeColor','none');alpha(0.5);
  580. plot(time2,psthE,'Color',exc,'linewidth',1);
  581. plot([-2 2],[0 0],':','color','k','linewidth',0.75);
  582. plot([0 0],[-3 9],':','color','k','linewidth',0.75);
  583. axis([-2 2 min(downE)-0.2 max(upE)+0.3]);
  584. title(['PE excitations (' num2str(round(100*sum(Sel)/sum(Reg))) '%)'])
  585. ylabel('Z-score');
  586. %% Plotting neurons that respond to reward
  587. %inhibitions
  588. Sel=Reg&R_2R.Ev(RD).RespDir<0; %Find neurons that have an inhibitory response to this event
  589. %average firing rate
  590. subplot(4,6,6+(i-1)*12);
  591. psthI=nanmean(R_2R.Ev(RD).PSTHz(Sel,Ushow),1); %find the average firing rate of the neurons at the time of the event
  592. semI=nanste(R_2R.Ev(RD).PSTHz(Sel,Ushow),1); %calculate standard error of the mean
  593. upI=psthI+semI;
  594. downI=psthI-semI;
  595. hold on;
  596. patch([time2,time2(end:-1:1)],[upI,downI(end:-1:1)],inh,'EdgeColor','none');alpha(0.5);
  597. plot(time2,psthI,'Color',inh,'linewidth',1); title('Mean firing (z-score)'); %create plot of avg firing rate
  598. plot([-1 2],[0 0],':','color','k','linewidth',0.75);
  599. plot([0 0],[-3 9],':','color','k','linewidth',0.75);
  600. axis([-1 2 min(downI)-0.2 max(upI)+0.2]);
  601. title(['RD inhibitions (' num2str(round(100*sum(Sel)/sum(Reg))) '%)'])
  602. ylabel('Z-score');
  603. %excitation
  604. Sel=Reg&R_2R.Ev(RD).RespDir>0; %Find neurons that have an excitatory response to this event
  605. %average firing rate
  606. subplot(4,6,12+(i-1)*12);
  607. psthE=nanmean(R_2R.Ev(RD).PSTHz(Sel,Ushow),1);
  608. semE=nanste(R_2R.Ev(RD).PSTHz(Sel,Ushow),1); %calculate standard error of the mean
  609. upE=psthE+semE;
  610. downE=psthE-semE;
  611. hold on;
  612. patch([time2,time2(end:-1:1)],[upE,downE(end:-1:1)],exc,'EdgeColor','none');alpha(0.5);
  613. plot(time2,psthE,'Color',exc,'linewidth',1);
  614. plot([-1 2],[0 0],':','color','k','linewidth',0.75);
  615. plot([0 0],[-3 9],':','color','k','linewidth',0.75);
  616. axis([-1 2 min(downE)-0.2 max(upE)+0.3]);
  617. title(['RD excitations (' num2str(round(100*sum(Sel)/sum(Reg))) '%)'])
  618. ylabel('Z-score');
  619. end
  620. %% plotting firing rate on sucrose and maltodextrin trials
  621. figure;
  622. %color map
  623. [magma,inferno,plasma,viridis]=colormaps;
  624. colormap(plasma);
  625. c=[-100 2000];ClimE=sign(c).*abs(c).^(1/4);%colormap
  626. Xaxis=[-1 4];
  627. Ishow=find(R_2R.Param.Tm>=Xaxis(1) & R_2R.Param.Tm<=Xaxis(2));
  628. time1=R_2R.Param.Tm(Ishow);
  629. Xaxis2=[-1 4];
  630. Ushow=find(R_2R.Param.Tm>=Xaxis2(1) & R_2R.Param.Tm<=Xaxis2(2));
  631. time2=R_2R.Param.Tm(Ushow);
  632. sucrose=[1 0.6 0.1];
  633. maltodextrin=[.9 0.3 .9];
  634. water=[0.00 0.75 0.75];
  635. total=[0.3 0.1 0.8];
  636. exc=[0 113/255 188/255];
  637. inh=[240/255 0 50/255];
  638. RD=strcmp('RD', R_2R.Erefnames);
  639. RD1=strcmp('RD1', R_2R.Erefnames);
  640. RD2=strcmp('RD2', R_2R.Erefnames);
  641. for i=1:2
  642. if i==1 Reg=NAneurons; end %1 is NAc
  643. if i==2 Reg=VPneurons; end %2 is VP
  644. %% Plotting heatmaps of sucrose and maltodextrin response
  645. Sel=Reg&R_2R.Ev(RD).RespDir<2; %gets all neurons
  646. %sort RD1 heatmap by magnitude of response
  647. Neurons=R_2R.Ev(RD1).PSTHz(Sel,Ushow); %get the firing rates of neurons of interest
  648. TMP=R_2R.Ev(RD).Meanz(Sel); %find the magnitude of the inhibitions for this event
  649. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  650. [~,SORTimg]=sort(TMP);
  651. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  652. %heatmap
  653. subplot(2,40,[1:9]+(i-1)*40);
  654. imagesc(time2,[1,sum(Sel,1)],Neurons,ClimE); title('Sucrose trials');
  655. ylabel('Individual neurons sorted by RD response');
  656. xlabel('Seconds from RD');
  657. hold on;
  658. plot([0 0],[0 sum(Sel)],':','color','k','linewidth',0.75);
  659. %sort RD2 heatmap the same way
  660. Neurons=R_2R.Ev(RD2).PSTHz(Sel,Ushow); %get the firing rates of neurons of interest
  661. [~,SORTimg]=sort(TMP);
  662. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  663. xlabel('Seconds from RD');
  664. %heatmap
  665. subplot(2,40,[13:21]+(i-1)*40);
  666. imagesc(time2,[1,sum(Sel,1)],Neurons,ClimE); title('Maltodextrin trials');
  667. xlabel('Seconds from RD');
  668. hold on;
  669. plot([0 0],[0 sum(Sel)],':','color','k','linewidth',0.75);
  670. %% Plotting average firing rate of reward excitations
  671. Sel=Reg&(R_2R.Ev(RD).RespDir>0); %| R_2R.Ev(LickR1).RespDir>0 | R_2R.Ev(LickR2).RespDir>0); %Find neurons that have an inhibitory response to this event
  672. %average firing rate to sucrose
  673. psth1=nanmean(R_2R.Ev(RD1).PSTHz(Sel,Ishow),1);
  674. sem1=nanste(R_2R.Ev(RD1).PSTHz(Sel,Ishow),1); %calculate standard error of the mean
  675. up1=psth1+sem1;
  676. down1=psth1-sem1;
  677. %average firing rate to maltodextrin
  678. psth2=nanmean(R_2R.Ev(RD2).PSTHz(Sel,Ishow),1);
  679. sem2=nanste(R_2R.Ev(RD2).PSTHz(Sel,Ishow),1); %calculate standard error of the mean
  680. up2=psth2+sem2;
  681. down2=psth2-sem2;
  682. %plotting
  683. subplot(4,5,[9 10]+(i-1)*10);
  684. hold on;
  685. plot(time1,psth1,'Color',sucrose,'linewidth',1);
  686. plot(time1,psth2,'Color',maltodextrin,'linewidth',1);
  687. patch([time1,time1(end:-1:1)],[up1,down1(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  688. patch([time1,time1(end:-1:1)],[up2,down2(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  689. plot([-1 4],[0 0],':','color','k','linewidth',0.75);
  690. plot([0 0],[-3 9],':','color','k','linewidth',0.75);
  691. axis([-1 4 min(down1)-0.2 max(up1)+0.3]);
  692. title(['Reward-excited (n=' num2str(sum(Sel)) ')'])
  693. ylabel('Mean firing (z-score)');
  694. xlabel('Seconds from RD');
  695. legend('Suc trials','Mal trials');
  696. % %onset
  697. % subplot(2,4,4);
  698. % cumul(R_2R.Ev(38).Onsets(Sel,1),[R_2R.Param.RespWin(1,1):0.04:R_2R.Param.RespWin(38,2)],2,maltodextrin);
  699. %% Plotting average firing rate of reward inhibitions
  700. Sel=Reg&(R_2R.Ev(RD).RespDir<0); %| R_2R.Ev(LickR1).RespDir<0 | R_2R.Ev(LickR2).RespDir<0); %Find neurons that have an inhibitory response to this event
  701. %avg firing rate to sucrose
  702. psth1=nanmean(R_2R.Ev(12).PSTHz(Sel,Ushow),1);
  703. sem1=nanste(R_2R.Ev(12).PSTHz(Sel,Ushow),1); %calculate standard error of the mean
  704. up1=psth1+sem1;
  705. down1=psth1-sem1;
  706. %avg firing rate to maltodextrin
  707. psth2=nanmean(R_2R.Ev(13).PSTHz(Sel,Ushow),1);
  708. sem2=nanste(R_2R.Ev(13).PSTHz(Sel,Ushow),1); %calculate standard error of the mean
  709. up2=psth2+sem2;
  710. down2=psth2-sem2;
  711. %plotting
  712. subplot(4,5,[4 5]+(i-1)*10);
  713. hold on;
  714. plot(time2,psth1,'Color',sucrose,'linewidth',1);
  715. plot(time2,psth2,'Color',maltodextrin,'linewidth',1);
  716. patch([time2,time2(end:-1:1)],[up2,down2(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  717. patch([time2,time2(end:-1:1)],[up1,down1(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  718. plot([-1 4],[0 0],':','color','k','linewidth',0.75);
  719. plot([0 0],[-3 9],':','color','k','linewidth',0.75);
  720. axis([-1 4 min(down1)-0.2 max(up1)+0.2]);
  721. title(['Reward-inhibited (n=' num2str(sum(Sel)) ')'])
  722. ylabel('Mean firing (z-score)');
  723. xlabel('Seconds from RD');
  724. legend('Suc trials','Mal trials','location','southeast');
  725. end