l_Figure5_Figure6_BehaviorAndSingleUnitActivityAlcoholExposed.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. %% Code for final figures for pavlovian versus instrumental comparison
  2. clear all;
  3. if ~exist('RvppasALL'),load('RvppasALL.mat'); end
  4. if ~exist('RvpppasALL'),load('RvpppasALL.mat'); end
  5. DarkPurple=[123/255 50/255 148/255];
  6. LightPurple=[194/255 165/255 207/255];
  7. LightGreen=[166/255 219/255 160/255];
  8. DarkGreen=[77/255 172/255 38/255];
  9. DarkPink=[208/255 28/255 139/255];
  10. MyBlue=[0.4940 0.1840 0.5560];
  11. MyOrange=[0.9290 0.6940 0.1250];
  12. DS=[51/255 160/255 44/255];
  13. Pav=[180/255 41/255 230/255];
  14. BSIZE=0.01;
  15. Dura=[-0.5 1]; Tm=Dura(1):BSIZE:Dura(2);
  16. Baseline=[-2 0]; Tbase=Baseline(1):BSIZE:Baseline(2); %used to calculate Z-scores
  17. Tbin=-1:0.005:1; %window used to determine the optimal binsize
  18. PStat=0.05;
  19. prewin=[Dura(1) 0];
  20. postwin=[.1 .3];
  21. postwin2=[Dura(1):0.05:Dura(2)]; %bounds should match Dura
  22. Slopebounds=[-.5:.05:.5];
  23. R2Bounds=[0:0.05:0.5];
  24. PvalBounds=[0:0.01:0.5];
  25. Struct=10;
  26. %% Figure 1 VP neurons encode cue value in both tasks
  27. BrainRegion=1; %10 for Core, 100 for dms and 1000 for shell
  28. LeftEv=1; RightEv=2;
  29. ExcInh=1; % 1 for excitations, 2 for inhibitions -- Used to find Exc or Inh onsets in R.Ev(.).Onsets
  30. Pstat=0.05;
  31. stepsize=0.3; % Used for the scatter plot projections
  32. %For COLOR-CODED PSTH only (not Average PSTH)
  33. Norm=0; % 0 = no norm - max accross all the selected neurons
  34. % 1 each neuron is normalized wh its own max
  35. % 2 for baseline substraction
  36. if LeftEv==1, Xaxis=[-0.25 .5]; elseif LeftEv==3, Xaxis=[-0.25 .5]; elseif LeftEv==5; Xaxis=[-3 3]; elseif LeftEv==7; Xaxis=[-1 2]; elseif LeftEv==9; Xaxis=[-0.25 1]; end
  37. if ExcInh==1, Yaxis=[-5 10]; elseif ExcInh==2, Yaxis=[-5 5]; end
  38. %----------- COLORS ---------
  39. myblue=[0 113/255 188/255];
  40. mypurple=[200/255 0 255/255];
  41. mydarkblue=[0 0/255 255/255];
  42. TickSize=[0.015 0.02];
  43. DarkPurple=[123/255 50/255 148/255];
  44. LightPurple=[194/255 165/255 207/255];
  45. LightGreen=[166/255 219/255 160/255];
  46. DarkGreen=[77/255 172/255 38/255];
  47. DarkPink=[208/255 28/255 139/255];
  48. Ishow=find(RvppasALL.Param.Tm>=Xaxis(1) & RvppasALL.Param.Tm<=Xaxis(2));
  49. time=RvppasALL.Param.Tm(Ishow);
  50. if ExcInh==1, A=1; elseif ExcInh==2; A=-1;end
  51. figure;
  52. for i=1:2 %plots 3 different conditions (eg LP+No0 / LP+No+ / LP0No+)
  53. selectionInst=RvpppasALL.Structure==10 & ~isnan(RvpppasALL.Ev(LeftEv).Meanz) & ~isnan(RvpppasALL.Ev(RightEv).Meanz) & RvpppasALL.CSPlusRatio>=.5 & (RvpppasALL.CSPlusRatio./(RvpppasALL.CSPlusRatio+RvpppasALL.CSMinusRatio))>=.7;% & strcmp(RvpppasALL.Ninfo(:,1),'PA168Sess13_sorted-01.nex');%'PA167Sess07_sorted.nex''PA168Sess13_sorted-01.nex' & RvpppasALL.Ev(1).RespDir==0;% & CvpppasALL.STATSpost>=0.05;
  54. selectionPav=RvppasALL.Structure==10 & ~isnan(RvppasALL.Ev(LeftEv).Meanz) & ~isnan(RvppasALL.Ev(RightEv).Meanz) & RvppasALL.CSPlusRatio>=.5 & (RvppasALL.CSPlusRatio./(RvppasALL.CSPlusRatio+RvppasALL.CSMinusRatio))>=.7;% & RvppasALL.Ev(1).RespDir==0;% & CvppasALL.STATSpost>=0.05;
  55. %------------- SORTING -------------
  56. SortEv=LeftEv; NonSortEv=RightEv;
  57. if i==1;
  58. selection=selectionInst;
  59. TMP=-RvpppasALL.Ev(SortEv).Meanz(selection,ExcInh);
  60. %TMP=RvpppasALL.Ev(SortEv).RespDir(selection,ExcInh);
  61. else;
  62. selection=selectionPav;
  63. TMP=-RvppasALL.Ev(SortEv).Meanz(selection,ExcInh);
  64. %TMP=RvppasALL.Ev(SortEv).RespDir(selection,ExcInh);
  65. end
  66. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  67. [~,SORTimg]=sort(TMP);
  68. %NNids are the indexes for the 3 different selections
  69. if i==1; NNid1=cell2mat(RvpppasALL.Ninfo(selection,3)); NNid1=NNid1(SORTimg); end
  70. if i==2; NNid2=cell2mat(RvppasALL.Ninfo(selection,3)); NNid2=NNid2(SORTimg); end
  71. if i==1,
  72. selection=selectionInst; SortEv=LeftEv; NonSortEv=RightEv;
  73. % ------------- NORMALIZATION -------------
  74. if Norm==0
  75. imgLeft=RvpppasALL.Ev(LeftEv).PSTHz(selection,Ishow);
  76. imgRight=RvpppasALL.Ev(RightEv).PSTHz(selection,Ishow);
  77. E=[-200 400];Clim=sign(E).*abs(E).^(1/4);%ColorMap
  78. elseif Norm~=0
  79. imgLeft=normalize(RvpppasALL.Ev(LeftEv).PSTHz(selection,Ishow),RvpppasALL.Ev(LeftEv).PSTHz(selection,(RvpppasALL.Param.Tm<0)),Norm); %normalize to max response
  80. imgRight=normalize(RvpppasALL.Ev(RightEv).PSTHz(selection,Ishow),RvpppasALL.Ev(LeftEv).PSTHz(selection,(RvpppasALL.Param.Tm<0)),Norm); %normalize to max response of the left event
  81. if Norm==1, Clim=[0 1]; elseif Norm==2, Clim=[-5 10]; end
  82. end
  83. imgLeft=imgLeft(SORTimg,:);
  84. imgRight=imgRight(SORTimg,:);
  85. else if i==2,
  86. selection=selectionPav; SortEv=LeftEv; NonSortEv=RightEv;
  87. if Norm==0
  88. imgLeft=RvppasALL.Ev(LeftEv).PSTHz(selection,Ishow);
  89. imgRight=RvppasALL.Ev(RightEv).PSTHz(selection,Ishow);
  90. E=[-200 400];Clim=sign(E).*abs(E).^(1/4);%ColorMap
  91. elseif Norm~=0
  92. imgLeft=normalize(RvppasALL.Ev(LeftEv).PSTHz(selection,Ishow),RvppasALL.Ev(LeftEv).PSTHz(selection,(RvppasALL.Param.Tm<0)),Norm); %normalize to max response
  93. imgRight=normalize(RvppasALL.Ev(RightEv).PSTHz(selection,Ishow),RvppasALL.Ev(LeftEv).PSTHz(selection,(RvppasALL.Param.Tm<0)),Norm); %normalize to max response of the left event
  94. if Norm==1, Clim=[0 1]; elseif Norm==2, Clim=[-5 10]; end
  95. end
  96. imgLeft=imgLeft(SORTimg,:);
  97. imgRight=imgRight(SORTimg,:);
  98. end
  99. end
  100. %---------------- HEAT MAPS ----------------------
  101. subplot(3,4,i+((i-1)*3));
  102. imagesc(time,[1 size(imgLeft,1)],imgLeft,Clim); %colorbar;axis tight;
  103. colormap(parula);
  104. ylabel('Neuron #');
  105. xlabel('Time from Cue (sec)');
  106. if i==1;
  107. title('DS');
  108. elseif i==2;
  109. title('CS+');
  110. end
  111. subplot(3,4,i+1+((i-1)*3));
  112. imagesc(time,[1 size(imgRight,1)],imgRight,Clim) ;%colorbar;axis tight;
  113. colormap(parula);
  114. %title(Erefnames(RightEv));
  115. ylabel('Neuron #');
  116. xlabel('Time from Cue (sec)');
  117. if i==1;
  118. title('NS');
  119. elseif i==2;
  120. title('CS-');
  121. end
  122. subplot(3,2,i*2);
  123. hold on;
  124. if i==1 %PPS
  125. if LeftEv==1, Stat=RvpppasALL.CSStat;
  126. elseif LeftEv==3, Stat=RvpppasALL.CSPlusResponseStat;
  127. end
  128. selection1=selectionInst & Stat>=0.05;
  129. selection2=selectionInst & Stat<0.05 & RvpppasALL.Ev(LeftEv).Meanz>RvpppasALL.Ev(RightEv).Meanz;
  130. selection3=selectionInst & Stat<0.05 & RvpppasALL.Ev(LeftEv).Meanz<RvpppasALL.Ev(RightEv).Meanz;
  131. scatter(RvpppasALL.Ev(LeftEv).Meanz(selection1),RvpppasALL.Ev(RightEv).Meanz(selection1),30, 'k');%,'filled');
  132. scatter(RvpppasALL.Ev(LeftEv).Meanz(selection2),RvpppasALL.Ev(RightEv).Meanz(selection2),30, DarkPink);
  133. scatter(RvpppasALL.Ev(LeftEv).Meanz(selection3),RvpppasALL.Ev(RightEv).Meanz(selection3),30, DarkGreen);
  134. %selection4= R.Ev(RightEv).RespDir==1 & R.Ev(6).RespDir==1;
  135. %scatter(R.Ev(LeftEv).Meanz(selection4),R.Ev(RightEv).Meanz(selection4),30,'g','filled');
  136. xlabel('DS Response Magnitude (z-score)');
  137. ylabel('NS Response magnitude (z-score)');
  138. legend('DS=NS','DS>NS','DS<NS','Location','northwest');
  139. else %PS
  140. if LeftEv==1, Stat=RvppasALL.CSStat;
  141. elseif LeftEv==3, Stat=RvppasALL.CSResponseStat;
  142. end
  143. selection1=selectionPav & Stat>=0.05;
  144. selection2=selectionPav & Stat<0.05 & RvppasALL.Ev(LeftEv).Meanz>RvppasALL.Ev(RightEv).Meanz;
  145. selection3=selectionPav & Stat<0.05 & RvppasALL.Ev(LeftEv).Meanz<RvppasALL.Ev(RightEv).Meanz;
  146. scatter(RvppasALL.Ev(LeftEv).Meanz(selection1),RvppasALL.Ev(RightEv).Meanz(selection1),30, 'k');%,'filled');
  147. scatter(RvppasALL.Ev(LeftEv).Meanz(selection2),RvppasALL.Ev(RightEv).Meanz(selection2),30, DarkPink);
  148. scatter(RvppasALL.Ev(LeftEv).Meanz(selection3),RvppasALL.Ev(RightEv).Meanz(selection3),30, DarkGreen);
  149. Min=floor(min([RvppasALL.Ev(LeftEv).Meanz(selection2);RvppasALL.Ev(RightEv).Meanz(selection2)]));
  150. Max=ceil(max([RvppasALL.Ev(LeftEv).Meanz(selection2);RvppasALL.Ev(RightEv).Meanz(selection2)]));
  151. xlabel('CS+ Response Magnitude (z-score)');
  152. ylabel('CS- Response magnitude (z-score)');
  153. legend('CS+=CS-','CS+>CS-','CS+<CS-','Location','northwest');
  154. end
  155. Min=floor(min([RvpppasALL.Ev(LeftEv).Meanz(RvpppasALL.Structure==10);RvpppasALL.Ev(RightEv).Meanz(RvpppasALL.Structure==10)]));
  156. Max=ceil(max([RvpppasALL.Ev(LeftEv).Meanz(RvpppasALL.Structure==10);RvpppasALL.Ev(RightEv).Meanz(RvpppasALL.Structure==10)]));
  157. line([Min Max],[Min Max],'Color', 'k');
  158. line([Min Max], [0 0],'Color', 'k');
  159. line([0 0], [Min Max],'Color', 'k');
  160. subplot(10,6,58); %Histograms for scatterplots
  161. if LeftEv==1, Stat=RvpppasALL.CSStat;
  162. elseif LeftEv==3, Stat=RvpppasALL.CSPlusResponseStat;
  163. end
  164. axis([-10 10 0 .25]);
  165. edges = [-10:1:9];
  166. selection1=selectionInst & Stat>=0.05;
  167. selection2=selectionInst & Stat<0.05 & RvpppasALL.Ev(LeftEv).Meanz>RvpppasALL.Ev(RightEv).Meanz;
  168. selection3=selectionInst & Stat<0.05 & RvpppasALL.Ev(LeftEv).Meanz<RvpppasALL.Ev(RightEv).Meanz;
  169. Delta1= RvpppasALL.Ev(LeftEv).Meanz(selection1)-RvpppasALL.Ev(RightEv).Meanz(selection1);
  170. Delta2= RvpppasALL.Ev(LeftEv).Meanz(selection2)-RvpppasALL.Ev(RightEv).Meanz(selection2);
  171. Delta3= RvpppasALL.Ev(LeftEv).Meanz(selection3)-RvpppasALL.Ev(RightEv).Meanz(selection3);
  172. Delta1Hist=hist(Delta1,edges)/314;
  173. Delta2Hist=hist(Delta2,edges)/314;
  174. Delta3Hist=hist(Delta3,edges)/314;
  175. edges = [-10:1:10];
  176. histogram('FaceColor','k', 'BinEdges',edges,'BinCounts',Delta1Hist);
  177. hold on;
  178. histogram('FaceColor',DarkPink, 'BinEdges',edges,'BinCounts',Delta2Hist);
  179. histogram('FaceColor',DarkGreen, 'BinEdges',edges,'BinCounts',Delta3Hist);
  180. subplot(10,6,59); %Histograms for scatterplots
  181. if LeftEv==1, Stat=RvppasALL.CSStat;
  182. elseif LeftEv==3, Stat=RvppasALL.CSrespStat;
  183. end
  184. axis([-10 10 0 .25]);
  185. edges = [-10:1:9];
  186. selection1=selectionPav & Stat>=0.05;
  187. selection2=selectionPav & Stat<0.05 & RvppasALL.Ev(LeftEv).Meanz>RvppasALL.Ev(RightEv).Meanz;
  188. selection3=selectionPav & Stat<0.05 & RvppasALL.Ev(LeftEv).Meanz<RvppasALL.Ev(RightEv).Meanz;
  189. Delta1= RvppasALL.Ev(LeftEv).Meanz(selection1)-RvppasALL.Ev(RightEv).Meanz(selection1);
  190. Delta2= RvppasALL.Ev(LeftEv).Meanz(selection2)-RvppasALL.Ev(RightEv).Meanz(selection2);
  191. Delta3= RvppasALL.Ev(LeftEv).Meanz(selection3)-RvppasALL.Ev(RightEv).Meanz(selection3);
  192. Delta1Hist=hist(Delta1,edges)/392;
  193. Delta2Hist=hist(Delta2,edges)/392;
  194. Delta3Hist=hist(Delta3,edges)/392;
  195. edges = [-10:1:10];
  196. histogram('FaceColor','k', 'BinEdges',edges,'BinCounts',Delta1Hist);
  197. hold on;
  198. histogram('FaceColor',DarkPink, 'BinEdges',edges,'BinCounts',Delta2Hist);
  199. histogram('FaceColor',DarkGreen, 'BinEdges',edges,'BinCounts',Delta3Hist);
  200. selection1=selectionInst & ~isnan(RvpppasALL.Ev(LeftEv).Meanz) & ~isnan(RvpppasALL.Ev(RightEv).Meanz)& RvpppasALL.Ev(1).RespDir==1;% & CvpppasALL.STATSpost>=0.05;
  201. selection2=selectionPav & ~isnan(RvppasALL.Ev(LeftEv).Meanz) & ~isnan(RvppasALL.Ev(RightEv).Meanz)& RvppasALL.Ev(1).RespDir==1;% & CvppasALL.STATSpost>=0.05;
  202. %subplot of DS vs NS excited neurons
  203. if i==1
  204. selection=selection1;
  205. subplot(6,4,i+16);
  206. psthLeft=nanmean(RvpppasALL.Ev(LeftEv).PSTHz(selection,Ishow),1);
  207. semLeft=nanste(RvpppasALL.Ev(LeftEv).PSTHz(selection,Ishow),1);
  208. upLeft=psthLeft+semLeft;
  209. downLeft=psthLeft-semLeft;
  210. hold on;
  211. plot(time,psthLeft,'Color',DS,'linewidth',1.5);
  212. psthRight=nanmean(RvpppasALL.Ev(RightEv).PSTHz(selection,Ishow),1);
  213. semRight=nanste(RvpppasALL.Ev(RightEv).PSTHz(selection,Ishow),1);
  214. upRight=psthRight+semRight;
  215. downRight=psthRight-semRight;
  216. plot(time,psthRight,'k','linewidth',1.5);
  217. %legend('DS','NS','Location','northwest');
  218. patch([time,time(end:-1:1)],[upLeft,downLeft(end:-1:1)],DS,'EdgeColor','none');alpha(0.5);
  219. patch([time,time(end:-1:1)],[upRight,downRight(end:-1:1)],'k','EdgeColor','none');alpha(0.5);
  220. plot([0 0], [-10 20],'LineStyle',':','Color','k');
  221. plot([-10 20], [0 0],'LineStyle',':','Color','k');
  222. if LeftEv==3
  223. plot([1 1], [-10 20],'LineStyle',':','Color','k');
  224. plot([2.5 2.5], [-10 20],'LineStyle',':','Color','k');
  225. elseif LeftEv==5
  226. plot([-2 -2], [-10 20],'LineStyle',':','Color','k');
  227. plot([.5 .5], [-10 20],'LineStyle',':','Color','k');
  228. elseif LeftEv==7
  229. plot([1 1], [-10 20],'LineStyle',':','Color','k');
  230. plot([5 5], [-10 20],'LineStyle',':','Color','k');
  231. end
  232. axis([Xaxis,Yaxis]);
  233. %xlabel('Time from Cue (sec)');
  234. ylabel('Average Response (z-score)');
  235. else if i==2
  236. selection=selection2;
  237. subplot(6,4,i+19);
  238. psthLeft=nanmean(RvppasALL.Ev(LeftEv).PSTHz(selection,Ishow),1);
  239. semLeft=nanste(RvppasALL.Ev(LeftEv).PSTHz(selection,Ishow),1);
  240. upLeft=psthLeft+semLeft;
  241. downLeft=psthLeft-semLeft;
  242. hold on;
  243. plot(time,psthLeft,'Color',Pav,'linewidth',1.5);
  244. psthRight=nanmean(RvppasALL.Ev(RightEv).PSTHz(selection,Ishow),1);
  245. semRight=nanste(RvppasALL.Ev(RightEv).PSTHz(selection,Ishow),1);
  246. upRight=psthRight+semRight;
  247. downRight=psthRight-semRight;
  248. plot(time,psthRight,'k','linewidth',1.5);
  249. %legend('CS+','CS-','Location','northwest');
  250. patch([time,time(end:-1:1)],[upLeft,downLeft(end:-1:1)],Pav,'EdgeColor','none');alpha(0.5);
  251. patch([time,time(end:-1:1)],[upRight,downRight(end:-1:1)],'k','EdgeColor','none');alpha(0.5);
  252. plot([0 0], [-10 20],'LineStyle',':','Color','k');
  253. plot([-10 20], [0 0],'LineStyle',':','Color','k');
  254. if LeftEv==3
  255. plot([1 1], [-10 20],'LineStyle',':','Color','k');
  256. plot([2.5 2.5], [-10 20],'LineStyle',':','Color','k');
  257. elseif LeftEv==5
  258. plot([-2 -2], [-10 20],'LineStyle',':','Color','k');
  259. plot([.5 .5], [-10 20],'LineStyle',':','Color','k');
  260. elseif LeftEv==7
  261. plot([1 1], [-10 20],'LineStyle',':','Color','k');
  262. plot([5 5], [-10 20],'LineStyle',':','Color','k');
  263. end
  264. axis([Xaxis,Yaxis]);
  265. xlabel('Time from Cue (sec)');
  266. ylabel('Average Response (z-score)');
  267. end
  268. end
  269. selection1=selectionInst & ~isnan(RvpppasALL.Ev(LeftEv).Meanz) & ~isnan(RvpppasALL.Ev(RightEv).Meanz)& RvpppasALL.Ev(1).RespDir==-1;% & CvpppasALL.STATSpost>=0.05;
  270. selection2=selectionPav & ~isnan(RvppasALL.Ev(LeftEv).Meanz) & ~isnan(RvppasALL.Ev(RightEv).Meanz)& RvppasALL.Ev(1).RespDir==-1;% & CvppasALL.STATSpost>=0.05;
  271. if i==1
  272. selection=selection1;
  273. subplot(6,4,i+17);
  274. psthLeft=nanmean(RvpppasALL.Ev(LeftEv).PSTHz(selection,Ishow),1);
  275. semLeft=nanste(RvpppasALL.Ev(LeftEv).PSTHz(selection,Ishow),1);
  276. upLeft=psthLeft+semLeft;
  277. downLeft=psthLeft-semLeft;
  278. hold on;
  279. plot(time,psthLeft,'Color',DS,'linewidth',1.5);
  280. psthRight=nanmean(RvpppasALL.Ev(RightEv).PSTHz(selection,Ishow),1);
  281. semRight=nanste(RvpppasALL.Ev(RightEv).PSTHz(selection,Ishow),1);
  282. upRight=psthRight+semRight;
  283. downRight=psthRight-semRight;
  284. plot(time,psthRight,'k','linewidth',1.5);
  285. legend('DS','NS','Location','northwest');
  286. patch([time,time(end:-1:1)],[upLeft,downLeft(end:-1:1)],DS,'EdgeColor','none');alpha(0.5);
  287. patch([time,time(end:-1:1)],[upRight,downRight(end:-1:1)],'k','EdgeColor','none');alpha(0.5);
  288. plot([0 0], [-10 20],'LineStyle',':','Color','k');
  289. plot([-10 20], [0 0],'LineStyle',':','Color','k');
  290. if LeftEv==3
  291. plot([1 1], [-10 20],'LineStyle',':','Color','k');
  292. plot([2.5 2.5], [-10 20],'LineStyle',':','Color','k');
  293. elseif LeftEv==5
  294. plot([-2 -2], [-10 20],'LineStyle',':','Color','k');
  295. plot([.5 .5], [-10 20],'LineStyle',':','Color','k');
  296. elseif LeftEv==7
  297. plot([1 1], [-10 20],'LineStyle',':','Color','k');
  298. plot([5 5], [-10 20],'LineStyle',':','Color','k');
  299. end
  300. axis([Xaxis,Yaxis]);
  301. %xlabel('Time from Cue (sec)');
  302. %ylabel('Average Response (z-score)');
  303. else if i==2
  304. selection=selection2;
  305. subplot(6,4,i+20);
  306. psthLeft=nanmean(RvppasALL.Ev(LeftEv).PSTHz(selection,Ishow),1);
  307. semLeft=nanste(RvppasALL.Ev(LeftEv).PSTHz(selection,Ishow),1);
  308. upLeft=psthLeft+semLeft;
  309. downLeft=psthLeft-semLeft;
  310. hold on;
  311. plot(time,psthLeft,'Color',Pav,'linewidth',1.5);
  312. psthRight=nanmean(RvppasALL.Ev(RightEv).PSTHz(selection,Ishow),1);
  313. semRight=nanste(RvppasALL.Ev(RightEv).PSTHz(selection,Ishow),1);
  314. upRight=psthRight+semRight;
  315. downRight=psthRight-semRight;
  316. plot(time,psthRight,'k','linewidth',1.5);
  317. legend('CS+','CS-','Location','northwest');
  318. patch([time,time(end:-1:1)],[upLeft,downLeft(end:-1:1)],Pav,'EdgeColor','none');alpha(0.5);
  319. patch([time,time(end:-1:1)],[upRight,downRight(end:-1:1)],'k','EdgeColor','none');alpha(0.5);
  320. plot([0 0], [-10 20],'LineStyle',':','Color','k');
  321. plot([-10 20], [0 0],'LineStyle',':','Color','k');
  322. if LeftEv==3
  323. plot([1 1], [-10 20],'LineStyle',':','Color','k');
  324. plot([2.5 2.5], [-10 20],'LineStyle',':','Color','k');
  325. elseif LeftEv==5
  326. plot([-2 -2], [-10 20],'LineStyle',':','Color','k');
  327. plot([.5 .5], [-10 20],'LineStyle',':','Color','k');
  328. elseif LeftEv==7
  329. plot([1 1], [-10 20],'LineStyle',':','Color','k');
  330. plot([5 5], [-10 20],'LineStyle',':','Color','k');
  331. end
  332. axis([Xaxis,Yaxis]);
  333. xlabel('Time from Cue (sec)');
  334. %ylabel('Average Response (z-score)');
  335. end
  336. end
  337. end
  338. subplot(9,2,[14 16]);
  339. %Plot of auROC descriptions for CS versus DS on response versus no response
  340. %(percent of neurons!)
  341. sel1=RvpppasALL.Structure~=0;
  342. sel2=RvppasALL.Structure~=0;
  343. axis([0 1 0 .25]);
  344. %histogram(-RvpppasALL.CSauROC(RvpppasALL.Structure==10),[0:0.05:1],'Normalization','probability');
  345. cdfplot(-RvpppasALL.CSauROC(RvpppasALL.Structure==10 & RvpppasALL.CSPlusRatio>=.5 & (RvpppasALL.CSPlusRatio./(RvpppasALL.CSPlusRatio+RvpppasALL.CSMinusRatio))>=.7));
  346. hold on;
  347. cdfplot(-RvppasALL.CSauROC(RvppasALL.Structure==10 & RvppasALL.CSPlusRatio>=.5 & (RvppasALL.CSPlusRatio./(RvppasALL.CSPlusRatio+RvppasALL.CSMinusRatio))>=.7));
  348. %histogram(-RvppasALL.CSauROC(RvppasALL.Structure==10),[0:0.05:1],'Normalization','probability');
  349. MEANsel1=nanmedian(-RvpppasALL.CSauROC(RvpppasALL.Structure==10 & RvpppasALL.CSPlusRatio>=.5 & (RvpppasALL.CSPlusRatio./(RvpppasALL.CSPlusRatio+RvpppasALL.CSMinusRatio))>=.7));
  350. MEANsel2=nanmedian(-RvppasALL.CSauROC(RvppasALL.Structure==10 & RvppasALL.CSPlusRatio>=.5 & (RvppasALL.CSPlusRatio./(RvppasALL.CSPlusRatio+RvppasALL.CSMinusRatio))>=.7));
  351. plot([MEANsel1 MEANsel1], [0 1],'Color',DS);
  352. plot([MEANsel2 MEANsel2], [0 1],'Color',Pav);
  353. plot([.5 .5], [0 1],'Color','k');
  354. legend('DS','CS+','Location','northwest');
  355. xlabel('Cue Identity auROC');
  356. ylabel('Proportion of Neurons');
  357. task=cat(1,ones(length(RvpppasALL.CSauROC(selectionInst)),1),zeros(length(RvppasALL.CSauROC(selectionPav)),1));
  358. rat=cat(1,RvpppasALL.Rat(selectionInst),RvppasALL.Rat(selectionPav));
  359. tbl=table(cat(1,-RvpppasALL.CSauROC(selectionInst),-RvppasALL.CSauROC(selectionPav)),task,rat,'variablenames',{'auROC','Task','Subject'});
  360. %lme=fitlme(tbl,'auROC~Task+(1|Subject)');%+(1|Subject:Exposure)');
  361. %stats on firing of excited and inhibited neurons
  362. excitedNsP=selectionPav & (RvppasALL.Ev(1).RFLAG==1 | RvppasALL.Ev(1).RespDir==1) & RvppasALL.Ev(1).RFLAG~=-1 & RvppasALL.Ev(1).RespDir~=-1;
  363. excitedNsI=selectionInst & (RvpppasALL.Ev(1).RFLAG==1 | RvpppasALL.Ev(1).RespDir==1) & RvpppasALL.Ev(1).RFLAG~=-1 & RvpppasALL.Ev(1).RespDir~=-1;
  364. inhibNsI=selectionInst & (RvpppasALL.Ev(1).RFLAG==-1 | RvpppasALL.Ev(1).RespDir==-1) & RvpppasALL.Ev(1).RFLAG~=1 & RvpppasALL.Ev(1).RespDir~=1;
  365. inhibNsP=selectionPav & (RvppasALL.Ev(1).RFLAG==-1 | RvppasALL.Ev(1).RespDir==-1) & RvppasALL.Ev(1).RFLAG~=1 & RvppasALL.Ev(1).RespDir~=1;
  366. % [~,p,~,stats]=ttest(RvppasALL.Ev(1).Meanraw(excitedNsP),RvppasALL.Ev(2).Meanraw(excitedNsP)); %CS excited
  367. % [~,p,~,stats]=ttest(RvppasALL.Ev(1).Meanraw(inhibNsP),RvppasALL.Ev(2).Meanraw(inhibNsP)); %CS inhibited
  368. % [~,p,~,stats]=ttest(RvpppasALL.Ev(1).Meanraw(excitedNsI),RvpppasALL.Ev(2).Meanraw(excitedNsI)); %DS excited
  369. % [~,p,~,stats]=ttest(RvpppasALL.Ev(1).Meanraw(inhibNsI),RvpppasALL.Ev(2).Meanraw(inhibNsI)); %DS inhibited
  370. %---------------- COLOR SCALE ----------------------
  371. subplot(10,6,60);
  372. imagesc(time,[1 size(imgLeft,1)],imgLeft,Clim);colorbar;
  373. %ylabel('z-score');
  374. %
  375. % if SAVEFIG==1
  376. % Figpath='C:\Users\jricha95\Documents\Documents (3)\Experiments\New Experiments\PS PPS';
  377. % exportfig(figure(1), sprintf('%s\\Figure1cmyk.eps',Figpath), 'FontMode', 'fixed','FontSize', 12,'LineWidth', 0.5, 'Width', 10, 'format','eps2','color','cmyk','renderer', 'painters','resolution',300);
  378. % % %end
  379. %% Figure 5 pie charts
  380. figure;
  381. %Pie charts of response patterns
  382. %DS
  383. subplot(4,5,11);
  384. exc=sum((RvpppasALL.Ev(1).RFLAG(selectionInst)==1 | RvpppasALL.Ev(1).RespDir(selectionInst)==1) & RvpppasALL.Ev(1).RFLAG(selectionInst)~=-1 & RvpppasALL.Ev(1).RespDir(selectionInst)~=-1);
  385. inh=sum(RvpppasALL.Ev(1).RespDir(selectionInst)==-1 | RvpppasALL.Ev(1).RFLAG(selectionInst)==-1);
  386. no=sum(RvpppasALL.Ev(1).RFLAG(selectionInst)==0 & RvpppasALL.Ev(1).RespDir(selectionInst)==0);
  387. response=[exc inh no];
  388. labels = {'Excited','Inhibited','No Response'};
  389. pie(response);
  390. colormap([252/255 206/255 46/255; %// excitation yellow
  391. 50/255 67/255 186/255; %// inhibition blue
  392. 46/255 183/255 164/255]); %// no response teal
  393. title('DS');
  394. %CS+
  395. subplot(4,5,12);
  396. exc=sum((RvppasALL.Ev(1).RFLAG(selectionPav)==1 | RvppasALL.Ev(1).RespDir(selectionPav)==1) & RvppasALL.Ev(1).RFLAG(selectionPav)~=-1 & RvppasALL.Ev(1).RespDir(selectionPav)~=-1);
  397. inh=sum(RvppasALL.Ev(1).RespDir(selectionPav)==-1 | RvppasALL.Ev(1).RFLAG(selectionPav)==-1);
  398. no=sum(RvppasALL.Ev(1).RFLAG(selectionPav)==0 & RvppasALL.Ev(1).RespDir(selectionPav)==0);
  399. response=[exc inh no];
  400. pie(response);
  401. title('CS+');
  402. %DS port entry
  403. subplot(4,5,13);
  404. exc=sum((RvpppasALL.Ev(8).RFLAG(selectionInst)==1 | RvpppasALL.Ev(8).RespDir(selectionInst)==1) & RvpppasALL.Ev(5).RFLAG(selectionInst)~=-1 & RvpppasALL.Ev(5).RespDir(selectionInst)~=-1);
  405. inh=sum(RvpppasALL.Ev(8).RespDir(selectionInst)==-1 | RvpppasALL.Ev(8).RFLAG(selectionInst)==-1);
  406. no=sum(RvpppasALL.Ev(8).RFLAG(selectionInst)==0 & RvpppasALL.Ev(8).RespDir(selectionInst)==0);
  407. response=[exc inh no];
  408. labels = {'Excited','Inhibited','No Response'};
  409. pie(response);
  410. title('post-DS Port Entry');
  411. %CS+ port entry
  412. subplot(4,5,14);
  413. exc=sum((RvppasALL.Ev(8).RFLAG(selectionPav)==1 | RvppasALL.Ev(8).RespDir(selectionPav)==1) & RvppasALL.Ev(5).RFLAG(selectionPav)~=-1 & RvppasALL.Ev(5).RespDir(selectionPav)~=-1);
  414. inh=sum(RvppasALL.Ev(8).RespDir(selectionPav)==-1 | RvppasALL.Ev(8).RFLAG(selectionPav)==-1);
  415. no=sum(RvppasALL.Ev(8).RFLAG(selectionPav)==0 & RvppasALL.Ev(8).RespDir(selectionPav)==0);
  416. response=[exc inh no];
  417. h=pie(response);
  418. title('post-CS+ Port Entry');
  419. %CS+ reward
  420. subplot(4,5,15);
  421. exc=sum((RvppasALL.Ev(9).RFLAG(selectionPav)==1 | RvppasALL.Ev(9).RespDir(selectionPav)==1) & RvppasALL.Ev(7).RFLAG(selectionPav)~=-1 & RvppasALL.Ev(7).RespDir(selectionPav)~=-1);
  422. inh=sum(RvppasALL.Ev(9).RespDir(selectionPav)==-1 | RvppasALL.Ev(9).RFLAG(selectionPav)==-1);
  423. no=sum(RvppasALL.Ev(9).RFLAG(selectionPav)==0 & RvppasALL.Ev(9).RespDir(selectionPav)==0);
  424. response=[exc inh no];
  425. h=pie(response);
  426. title('post-CS+ Reward');
  427. %% Figure 5 behavior
  428. clear all;
  429. load('RAWvppsALL.mat')
  430. load('RAWvpppsALL.mat')
  431. load('RAWvppasALL.mat')
  432. load('RAWvpppasALL.mat')
  433. load('RPPSall.mat')
  434. load('RPSall.mat')
  435. load('RvppasALL.mat')
  436. load('RvpppasALL.mat')
  437. SessRat=[];
  438. for task=1:4
  439. if task==1 %inst suc
  440. RAW=RAWvpppsALL;
  441. R=RPPSall;
  442. elseif task==2 %inst suc(alc)
  443. RAW=RAWvpppasALL;
  444. R=RvpppasALL;
  445. elseif task==3 %pav suc
  446. RAW=RAWvppsALL;
  447. R=RPSall;
  448. elseif task==4 %pav suc(alc)
  449. RAW=RAWvppasALL;
  450. R=RvppasALL;
  451. end
  452. %which neurons are included
  453. selection=R.Structure==10 & R.CSPlusRatio>=.5 & (R.CSPlusRatio./(R.CSPlusRatio+R.CSMinusRatio))>=.7;
  454. %which sessions are included
  455. allsessions=unique(R.Ninfo(:,1)); %all sessions from this task
  456. [includedsessions,index]=unique(R.Ninfo(selection,1)); %all included sessions
  457. included=ismember(allsessions,includedsessions); %which of all sessions are included
  458. %get rat for each session
  459. Rats=R.Rat(index)+task*100; %make sure rats with same name from different experiment aren't accidentally combined
  460. SessRat=cat(1,SessRat,Rats,Rats); %twice to represent the CSPlus data and then the CSMinus data
  461. RAW=RAW(included);
  462. for i=1:length(RAW)
  463. if task==1 | task==3
  464. Ev1=strcmp('CSPlus1', RAW(i).Einfo(:,2));
  465. Ev2=strcmp('CSMinus1', RAW(i).Einfo(:,2));
  466. else
  467. Ev1=strcmp('CSPlus', RAW(i).Einfo(:,2));
  468. Ev2=strcmp('CSMinus', RAW(i).Einfo(:,2));
  469. end
  470. PE=strcmp('PortEntry', RAW(i).Einfo(:,2));
  471. CSPluses=RAW(i).Erast{Ev1};
  472. CSMinuses=RAW(i).Erast{Ev2};
  473. PortEntries=RAW(i).Erast{PE};
  474. CSPLatency=[];
  475. for j=1:length(CSPluses)
  476. if sum(PortEntries>CSPluses(j))>0
  477. CSPLatency(j,1)=min(PortEntries(PortEntries>CSPluses(j)))-CSPluses(j);
  478. else
  479. CSPLatency(j,1)=100;
  480. end
  481. end
  482. CSPLatency(CSPLatency>10)=[];
  483. CSMLatency=[];
  484. for j=1:length(CSMinuses)
  485. if sum(PortEntries>CSMinuses(j))>0
  486. CSMLatency(j,1)=min(PortEntries(PortEntries>CSMinuses(j)))-CSMinuses(j);
  487. else
  488. CSMLatency(j,1)=100; %will be removed
  489. end
  490. end
  491. CSMLatency(CSMLatency>10)=[];
  492. CSPMean{task,1}(i,1)=mean(CSPLatency,'omitnan');
  493. CSMMean{task,1}(i,1)=mean(CSMLatency,'omitnan');
  494. CSPlusProb{task,1}(i,1)=length(CSPLatency)/length(CSPluses);
  495. CSMinusProb{task,1}(i,1)=length(CSMLatency)/length(CSMinuses);
  496. end
  497. end
  498. %% plotting
  499. figure;
  500. DS=[0 0.4470 0.7410];
  501. Pav=[0.8500 0.3250 0.0980];
  502. DSAlcohol=[51/255 160/255 44/255];
  503. PavAlcohol=[180/255 41/255 230/255];
  504. black=[0 0 0];
  505. Colors=[DS;black;DSAlcohol;black;Pav;black;PavAlcohol;black];
  506. %probability
  507. data=[CSPlusProb{1,1};CSMinusProb{1,1};CSPlusProb{2,1};CSMinusProb{2,1};CSPlusProb{3,1};CSMinusProb{3,1};CSPlusProb{4,1};CSMinusProb{4,1}];
  508. group=[ones(size(CSPlusProb{1,1}));2*ones(size(CSMinusProb{1,1}));3*ones(size(CSPlusProb{2,1}));4*ones(size(CSMinusProb{2,1}));5*ones(size(CSPlusProb{3,1}));6*ones(size(CSMinusProb{3,1}));7*ones(size(CSPlusProb{4,1}));8*ones(size(CSMinusProb{4,1}))];
  509. task=[ones(size(CSPlusProb{1,1}));ones(size(CSMinusProb{1,1}));ones(size(CSPlusProb{2,1}));ones(size(CSMinusProb{2,1}));2*ones(size(CSPlusProb{3,1}));2*ones(size(CSMinusProb{3,1}));2*ones(size(CSPlusProb{4,1}));2*ones(size(CSMinusProb{4,1}))];
  510. exposure=[ones(size(CSPlusProb{1,1}));ones(size(CSMinusProb{1,1}));2*ones(size(CSPlusProb{2,1}));2*ones(size(CSMinusProb{2,1}));ones(size(CSPlusProb{3,1}));ones(size(CSMinusProb{3,1}));2*ones(size(CSPlusProb{4,1}));2*ones(size(CSMinusProb{4,1}))];
  511. cue=[ones(size(CSPlusProb{1,1}));2*ones(size(CSMinusProb{1,1}));ones(size(CSPlusProb{2,1}));2*ones(size(CSMinusProb{2,1}));ones(size(CSPlusProb{3,1}));2*ones(size(CSMinusProb{3,1}));ones(size(CSPlusProb{4,1}));2*ones(size(CSMinusProb{4,1}))];
  512. subplot(1,2,1);
  513. hold on;
  514. boxplot(data,group,'colors',Colors,'symbol','');
  515. for i=1:8
  516. scatter(i+((rand(sum(group==i),1)-0.5)/5),data(group==i),[],Colors(i,:),'filled')
  517. end
  518. plot([4.5 4.5],[0 0.9],'--','color','k');
  519. title('Port Entry Probability');
  520. xticks(1:8);
  521. xticklabels({'DS','NS','DS','NS','CS+','CS-','CS+','CS-'});
  522. text(0.8,0.6,'Sucrose','color',DS);
  523. text(2.8,0.8,'Suc(alc)','color',DSAlcohol);
  524. text(4.8,0.5,'Sucrose','color',Pav);
  525. text(6.8,0.6,'Suc(alc)','color',PavAlcohol);
  526. text(4.3,0.97,'ns','color','k');
  527. text(2,0.9,'<- ns ->','color','k','horizontalalignment','center');
  528. text(6,0.85,'<- ns ->','color','k','horizontalalignment','center');
  529. axis([0 9 0 1]);
  530. %stats
  531. %[~,ProbAnova,ProbStats]=anovan(data,{task,cue,SessRat},'varnames',{'Task','Cue','Subject'},'random',3,'nested',[0 0 0;0 0 0;1 0 0],'model','full');
  532. [~,ProbAnova,ProbStats]=anovan(data,{task,exposure,cue},'varnames',{'Task','Exposure','Cue'},'model','full','display','off');
  533. %[~,ProbAnova,ProbStats]=anovan(data(cue==1),{task(cue==1),exposure(cue==1)},'varnames',{'Task','Exposure'},'model','full','display','off');
  534. %multcompare(ProbStats,'dimension',[1 2]);
  535. %latency
  536. data=[CSPMean{1,1};CSMMean{1,1};CSPMean{2,1};CSMMean{2,1};CSPMean{3,1};CSMMean{3,1};CSPMean{4,1};CSMMean{4,1}];
  537. group=[ones(size(CSPMean{1,1}));2*ones(size(CSMMean{1,1}));3*ones(size(CSPMean{2,1}));4*ones(size(CSMMean{2,1}));5*ones(size(CSPMean{3,1}));6*ones(size(CSMMean{3,1}));7*ones(size(CSPMean{4,1}));8*ones(size(CSMMean{4,1}))];
  538. subplot(1,2,2);
  539. hold on;
  540. boxplot(data,group,'colors',Colors,'symbol','');
  541. for i=1:8
  542. scatter(i+((rand(sum(group==i),1)-0.5)/5),data(group==i),[],Colors(i,:),'filled')
  543. end
  544. plot([4.5 4.5],[0 8],'--','color','k');
  545. title('Port Entry Latency (sec)');
  546. xticks(1:8);
  547. xticklabels({'DS','NS','DS','NS','CS+','CS-','CS+','CS-'});
  548. xticklabels({'DS','NS','DS','NS','CS+','CS-','CS+','CS-'});
  549. text(0.8,7,'Sucrose','color',DS);
  550. text(2.8,6,'Suc(alc)','color',DSAlcohol);
  551. text(4.8,7.5,'Sucrose','color',Pav);
  552. text(6.8,7,'Suc(alc)','color',PavAlcohol);
  553. text(2,1.5,'<- ns ->','color','k','horizontalalignment','center');
  554. text(6,1.5,'<- ns ->','color','k','horizontalalignment','center');
  555. text(4.3,8.5,'*','color','k');
  556. axis([0 9 0 9]);
  557. %stats
  558. %[~,LatAnova,LatStats]=anovan(data,{task,cue,SessRat},'varnames',{'Task','Cue','Subject'},'random',3,'nested',[0 0 0;0 0 0;1 0 0],'model','full');
  559. [~,LatAnova,LatStats]=anovan(data,{task,exposure,cue},'varnames',{'Task','Exposure','Cue'},'model','full','display','off');
  560. %[~,LatAnova,LatStats]=anovan(data(cue==1),{task(cue==1),exposure(cue==1)},'varnames',{'Task','Exposure'},'model','full','display','off');
  561. %multcompare(LatStats,'dimension',[1 2]);