Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

k_Fig6ThreeRewards.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. %plotting 3rewards data
  2. clear all;
  3. load ('R_3R.mat');
  4. load ('RAW.mat');
  5. %get parameters
  6. BinBase=R_3R.Param.BinBase;
  7. BinDura=R_3R.Param.BinDura;
  8. bins=R_3R.Param.bins;
  9. binint=R_3R.Param.binint;
  10. binstart=R_3R.Param.binstart;
  11. PStatBins=0.01; %using more stringent cutoff to reduce pre-delivery noise
  12. %which bins bound the area examined for reward-selectivity? (in seconds)
  13. Time1=0.4; %seconds
  14. Time2=3; %seconds
  15. Bin1=(((Time1-BinDura(2)/2)-binstart)/binint); %convert to bin name
  16. Bin2=(((Time2-BinDura(2)/2)-binstart)/binint); %convert to bin name
  17. %sorting bin -- which bin the neurons' activity is sorted on for heatmap(in seconds)
  18. SortBinTime=1.1; %seconds
  19. SortBin=round((((SortBinTime-BinDura(2)/2)-binstart)/binint)); %convert to bin name
  20. sucrose=[1 0.6 0.1];
  21. maltodextrin=[.9 0.3 .9];
  22. water=[0.00 0.75 0.75];
  23. total=[0.3 0.1 0.8];
  24. exc=[0 113/255 188/255];
  25. inh=[240/255 0 50/255];
  26. %% conduct lick analysis
  27. global Dura Tm BSIZE Tbin
  28. path='C:\Users\dottenh2\Documents\MATLAB\David\2Rewards Nex Files\3RLick_paper.xls';
  29. %Main settings
  30. BSIZE=0.01; %Do not change
  31. Dura=[-22 20]; Tm=Dura(1):BSIZE:Dura(2);
  32. Tbin=-0.5:0.005:0.5; %window used to determine the optimal binsize
  33. MinNumTrials=5;
  34. Lick=[];Lick.Ninfo={};LL=0;Nlick=0;
  35. %Smoothing
  36. Smoothing=1; %0 for raw and 1 for smoothing
  37. SmoothTYPE='lowess'; %can change this between lowess and rlowess (more robust, ignores outliers more)
  38. SmoothSPAN=50; %percentage of total data points
  39. if Smoothing~=1, SmoothTYPE='NoSmoothing';SmoothSPAN=NaN; end
  40. % List of events to analyze and analysis windows EXTRACTED from excel file
  41. [~,Erefnames]=xlsread(path,'Windows','a3:a8'); % cell that contains the event names
  42. %Finds the total number of sessions
  43. for i=1:length(RAW)
  44. if strcmp('TH',RAW(i).Type(1:2))
  45. Nlick=Nlick+1;
  46. Lick.Linfo(i,1)=RAW(i).Ninfo(1,1);
  47. end
  48. end
  49. Lick.Erefnames= Erefnames;
  50. %preallocating the result matrix
  51. for k=1:length(Erefnames)
  52. Lick.Ev(k).PSTHraw(1:Nlick,1:length(Tm))=NaN(Nlick,length(Tm));
  53. Lick.Ev(k).BW(1:Nlick,1)=NaN;
  54. Lick.Ev(k).NumberTrials(1:Nlick,1)=NaN;
  55. end
  56. for i=1:length(RAW) %loops through sessions
  57. if strcmp('TH',RAW(i).Type(1:2))
  58. LL=LL+1; %lick session counter
  59. for k=1:length(Erefnames) %loops thorough the events
  60. EvInd=strcmp(Erefnames(k),RAW(i).Einfo(:,2)); %find the event id number from RAW
  61. LickInd=strcmp('Licks',RAW(i).Einfo(:,2)); %find the event id number from RAW
  62. if sum(EvInd)==0
  63. fprintf('HOWDY, CANT FIND EVENTS FOR ''%s''\n',Erefnames{k});
  64. end
  65. Lick.Ev(k).NumberTrials(LL,1)=length(RAW(i).Erast{EvInd});
  66. if ~isempty(EvInd) && Lick.Ev(k).NumberTrials(LL,1)>MinNumTrials %avoid analyzing sessions where that do not have enough trials
  67. [PSR1,N1]=MakePSR04(RAW(i).Erast(LickInd),RAW(i).Erast{EvInd},Dura,{1});% makes collpased rasters. PSR1 is a cell(neurons)
  68. if ~isempty(PSR1{1}) %to avoid errors, added on 12/28 2011
  69. %forcing 100ms bin size to keep it consistent across
  70. %sessions (no reason is should be different for licks)
  71. [PTH1,BW1,~]=MakePTH07(PSR1,repmat(N1, size(RAW(i).Erast{LickInd},1),1),{2,0,0.1});%these values force bin size to be 100ms
  72. PTH1=smooth(PTH1,SmoothSPAN,SmoothTYPE)';
  73. %------------- Fills the R.Ev(k) fields --------------
  74. Lick.Ev(k).BW(LL,1)=BW1;
  75. Lick.Ev(k).PSTHraw(LL,1:length(Tm))=PTH1;
  76. end
  77. end
  78. end
  79. end
  80. end
  81. Xaxis=[-2 12];
  82. Ishow=find(Tm>=Xaxis(1) & Tm<=Xaxis(2));
  83. time1=Tm(Ishow);
  84. c=[-1000 7500];ClimE=sign(c).*abs(c).^(1/4);%ColorMapExc
  85. colormap(jet);
  86. sucrose=[1 0.6 0.1];
  87. maltodextrin=[.9 0.3 .9];
  88. water=[0.00 0.75 0.75];
  89. total=[0.3 0.1 0.8];
  90. exc=[0 113/255 188/255];
  91. inh=[240/255 0 50/255];
  92. Ev1=strcmp('RD1', Lick.Erefnames);
  93. Ev2=strcmp('RD2', Lick.Erefnames);
  94. Ev3=strcmp('RD3', Lick.Erefnames);
  95. psth1=nanmean(Lick.Ev(Ev1).PSTHraw(:,Ishow),1);
  96. sem1=nanste(Lick.Ev(Ev1).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  97. up1=psth1+sem1;
  98. down1=psth1-sem1;
  99. psthE=nanmean(Lick.Ev(Ev2).PSTHraw(:,Ishow),1);
  100. semE=nanste(Lick.Ev(Ev2).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  101. upE=psthE+semE;
  102. downE=psthE-semE;
  103. psth3=nanmean(Lick.Ev(Ev3).PSTHraw(:,Ishow),1);
  104. sem3=nanste(Lick.Ev(Ev3).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  105. up3=psth3+sem3;
  106. down3=psth3-sem3;
  107. %plotting
  108. subplot(2,3,1);
  109. hold on;
  110. plot(time1,psth1,'Color',sucrose,'linewidth',1);
  111. plot(time1,psthE,'Color',maltodextrin,'linewidth',1);
  112. plot(time1,psth3,'Color',water,'linewidth',1);
  113. patch([time1,time1(end:-1:1)],[up1,down1(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  114. patch([time1,time1(end:-1:1)],[upE,downE(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  115. patch([time1,time1(end:-1:1)],[up3,down3(end:-1:1)],water,'EdgeColor','none');alpha(0.5);
  116. title('Mean lick rate');
  117. %plot([-2 10],[0 0],':','color','k');
  118. plot([0 0],[-2 8],':','color','k','linewidth',0.75);
  119. axis([-2 12 0 7.5]);
  120. xlabel('Seconds from reward delivery');
  121. ylabel('Licks/s');
  122. legend('Sucrose trials','Maltodextrin trials','Water trials');
  123. %% bins analysis
  124. %first and last bin aren't included because you can't compare to the previous/subsequent bin
  125. %this axis plots the bins on their centers
  126. xaxis=linspace(binstart+binint+BinDura(2)/2,binstart+(bins-2)*binint+BinDura(2)/2,bins-2);
  127. for i=2:(bins-1) %no including first or last bin because can't compare to previous/subsequent bin
  128. %finds out whether firing is stronger (high excitation or lower inhibition) for 1 or 2
  129. for k=1:length(R_3R.Ninfo) %runs through neurons
  130. if R_3R.BinStatRwrd{i,1}(k).IntSig < PStatBins %if neuron is significant for this bin
  131. if R_3R.BinStatRwrd{i-1,1}(k).IntSig < PStatBins || R_3R.BinStatRwrd{i+1,1}(k).IntSig < PStatBins %either previous or subsequent bin must be significant
  132. if R_3R.BinStatRwrd{i,1}(k).R1Mean >= R_3R.BinStatRwrd{i,1}(k).R2Mean && R_3R.BinStatRwrd{i,1}(k).R1Mean >= R_3R.BinStatRwrd{i,1}(k).R3Mean %if firing is greater on sucrose trials than maltodextrin and water. if there's a tie, make it sucrose (this is highly unlikely)
  133. R_3R.BinRewPref{i,1}(k,1)=1; %sucrose preferring
  134. elseif R_3R.BinStatRwrd{i,1}(k).R2Mean > R_3R.BinStatRwrd{i,1}(k).R1Mean && R_3R.BinStatRwrd{i,1}(k).R2Mean >= R_3R.BinStatRwrd{i,1}(k).R3Mean %if mal is greater than suc and water
  135. R_3R.BinRewPref{i,1}(k,1)=2; %maltodextrin preferring
  136. else
  137. R_3R.BinRewPref{i,1}(k,1)=3; %water preferring
  138. end
  139. else
  140. R_3R.BinRewPref{i,1}(k,1)=0; %if not significant in 2 consecutive bins
  141. end
  142. else
  143. R_3R.BinRewPref{i,1}(k,1)=0; %if no sig reward modulation
  144. end
  145. end
  146. %find how many NAc neurons have significant reward modulation in each bin
  147. NN1perBin(i,1)=sum(R_3R.BinRewPref{i,1}(:,1)==1); %sucrose pref
  148. NN2perBin(i,1)=sum(R_3R.BinRewPref{i,1}(:,1)==2); %malto pref
  149. NN3perBin(i,1)=sum(R_3R.BinRewPref{i,1}(:,1)==3); %malto pref
  150. NNperBin(i,1)=sum(R_3R.BinRewPref{i,1}(:,1)>0); %any
  151. %normalize to number of neurons in population
  152. NN1norm=NN1perBin./length(R_3R.Ninfo);
  153. NN2norm=NN2perBin./length(R_3R.Ninfo);
  154. NN3norm=NN3perBin./length(R_3R.Ninfo);
  155. NNnorm=NNperBin./length(R_3R.Ninfo);
  156. end
  157. %plotting number of significantly modulated neurons across time
  158. %NAc
  159. subplot(2,3,2);
  160. hold on;
  161. plot(xaxis,NNnorm(2:bins-1),'Color', total,'linewidth',1.5);
  162. plot(xaxis,NN1norm(2:bins-1),'Color',sucrose,'linewidth',1.5);
  163. plot(xaxis,NN2norm(2:bins-1),'Color',maltodextrin,'linewidth',1.5);
  164. plot(xaxis,NN3norm(2:bins-1),'Color',water,'linewidth',1.5);
  165. plot([Time1 Time1],[-1 1],':','color','k','linewidth',0.75);
  166. plot([Time2 Time2],[-1 1],':','color','k','linewidth',0.75);
  167. axis([xaxis(1) xaxis(end) 0 0.85]);
  168. legend('Total','Suc > mal & wat','Mal > suc & wat','Water > suc & mal','Location','northeast')
  169. ylabel('Fraction of population');
  170. xlabel('Seconds from RD');
  171. title('Reward-selective neurons');
  172. %% plotting sucrose-selective neurons
  173. %color map
  174. [magma,inferno,plasma,viridis]=colormaps;
  175. colormap(plasma);
  176. c=[-100 2000];ClimE=sign(c).*abs(c).^(1/4);%colormap
  177. %events we're looking at
  178. RD1=strcmp('RD1', R_3R.Erefnames);
  179. RD2=strcmp('RD2', R_3R.Erefnames);
  180. RD3=strcmp('RD3', R_3R.Erefnames);
  181. %setting up parameters
  182. Xaxis=[-2 5];
  183. inttime=find(R_3R.Param.Tm>=Xaxis(1) & R_3R.Param.Tm<=Xaxis(2));
  184. paramtime=R_3R.Param.Tm(inttime);
  185. %find all neurons with greater firing for sucrose
  186. for i = 1:(Bin2-Bin1+1)
  187. %the added +1 is necessary because bin 20 is the 21st entry in the matrix
  188. Pref1(:,i)=R_3R.BinRewPref{Bin1+i}==1; %get neurons that have greater firing for sucrose in any of the bins bounded above
  189. Resp11(:,i)=Pref1(:,i)&cat(1,R_3R.BinStatRwrd{Bin1+i,1}.SucRespDir)==1; %get neurons with excitation to sucrose
  190. Resp12(:,i)=Pref1(:,i)&cat(1,R_3R.BinStatRwrd{Bin1+i,1}.MalRespDir)==1;%get neurons with inhibition to maltodextrin
  191. Resp13(:,i)=Pref1(:,i)&cat(1,R_3R.BinStatRwrd{Bin1+i,1}.WatRespDir)==-1;%get neurons with inhibition to maltodextrin
  192. end
  193. Sel=sum(Pref1,2)>0; %all neurons selective in any bin
  194. Sel1=sum(Resp11,2)>0; %all selective neurons sucrose excited in any bin
  195. Sel3=sum(Resp12,2)>0; %all selective neurons malto inhibited in any bin
  196. Sel6=sum(Resp13,2)>0; %all selective neurons malto inhibited in any bin
  197. subplot(2,4,5); %heatmap of suc preferring neurons' response to sucrose
  198. Neurons=R_3R.Ev(RD1).PSTHz(Sel,inttime); %get the firing rates of neurons of interest
  199. SucResp=cat(1,R_3R.BinStatRwrd{SortBin+1,1}.R1Mean); %sucrose responses
  200. TMP=SucResp(Sel); %find the magnitude of the excitations for water for this binTMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  201. [~,SORTimg]=sort(TMP);
  202. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  203. imagesc(paramtime,[1,sum(Sel,1)],Neurons,ClimE);
  204. title(['Sucrose trials']);
  205. xlabel('Seconds from RD');
  206. ylabel('Individual neurons');
  207. hold on;
  208. plot([0 0],[0 sum(Sel)],':','color','k','linewidth',0.75);
  209. subplot(2,4,6); %heatmap of suc preferring neurons' response to maltodextrin
  210. Neurons=R_3R.Ev(RD2).PSTHz(Sel,inttime); %get the firing rates of neurons of interest
  211. Neurons=Neurons(SORTimg,:); %sort the neurons same as before
  212. imagesc(paramtime,[1,sum(Sel,1)],Neurons,ClimE);
  213. title(['Maltodextrin trials']);
  214. xlabel('Seconds from RD');
  215. hold on;
  216. plot([0 0],[0 sum(Sel)],':','color','k','linewidth',0.75);
  217. subplot(2,4,7); %heatmap of suc preferring neurons' response to water
  218. Neurons=R_3R.Ev(RD3).PSTHz(Sel,inttime); %get the firing rates of neurons of interest
  219. Neurons=Neurons(SORTimg,:); %sort the neurons same as before
  220. imagesc(paramtime,[1,sum(Sel,1)],Neurons,ClimE);
  221. title(['Water trials']);
  222. xlabel('Seconds from RD');
  223. hold on;
  224. plot([0 0],[0 sum(Sel)],':','color','k','linewidth',0.75);
  225. %plot suc preferring neurons to suc
  226. psthE=nanmean(R_3R.Ev(RD1).PSTHz(Sel,inttime),1);
  227. semE=nanste(R_3R.Ev(RD1).PSTHz(Sel,inttime),1); %calculate standard error of the mean
  228. upE=psthE+semE;
  229. downE=psthE-semE;
  230. %plot suc preferring neurons to malt
  231. psth2=nanmean(R_3R.Ev(RD2).PSTHz(Sel,inttime),1);
  232. sem2=nanste(R_3R.Ev(RD2).PSTHz(Sel,inttime),1); %calculate standard error of the mean
  233. up2=psth2+sem2;
  234. down2=psth2-sem2;
  235. %plot suc preferring neurons to water
  236. psth3=nanmean(R_3R.Ev(RD3).PSTHz(Sel,inttime),1);
  237. sem3=nanste(R_3R.Ev(RD3).PSTHz(Sel,inttime),1); %calculate standard error of the mean
  238. up3=psth3+sem3;
  239. down3=psth3-sem3;
  240. %plotting
  241. subplot(2,3,3);
  242. hold on;
  243. plot(paramtime,psthE,'Color',sucrose,'linewidth',1);
  244. plot(paramtime,psth2,'Color',maltodextrin,'linewidth',1);
  245. plot(paramtime,psth3,'Color',water,'linewidth',1);
  246. patch([paramtime,paramtime(end:-1:1)],[upE,downE(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  247. patch([paramtime,paramtime(end:-1:1)],[up2,down2(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  248. patch([paramtime,paramtime(end:-1:1)],[up3,down3(end:-1:1)],water,'EdgeColor','none');alpha(0.5);
  249. legend('Suc trials','Mal trials','Wat trials');
  250. plot([-2 5],[0 0],':','color','k','linewidth',0.75);
  251. plot([0 0],[-2 8],':','color','k','linewidth',0.75);
  252. axis([-2 5 -2 4.7]);
  253. ylabel('Mean firing (z-score)');
  254. title(['Suc>mal&wat (n=' num2str(sum(Sel)) ' of ' num2str(length(Sel)) ')'])
  255. xlabel('Seconds from RD');
  256. G = sum(Sel1&Sel3&Sel6);
  257. F = sum(Sel3&Sel6);
  258. E = sum(Sel1&Sel6);
  259. D = sum(Sel1&Sel3);
  260. A = sum(Sel1);
  261. B = sum(Sel3);
  262. C = sum(Sel6);
  263. %vertical venn diagram
  264. x = [0 0 1 1];
  265. y1 = [C-E C-E+A C-E+A C-E];
  266. y2 = [C-F C-F+B C-F+B C-F];
  267. y3 = [0 C C 0];
  268. subplot(2,35,64);
  269. hold on;
  270. s = patch(x,y1,sucrose);
  271. m = patch(x,y2,maltodextrin);
  272. w = patch(x,y3,water);
  273. alpha(s,0.7);
  274. alpha(w,0.5);
  275. alpha(m,0.5);
  276. set(gca,'xtick',[]);
  277. ylabel('Distribution of neurons');
  278. axis([0 1 0 C-E+A]);
  279. %% stats on reward firing averaged together
  280. %for simplicity, just looking at average activity in sort bin
  281. %because I already have that data collected
  282. SucResp=cat(1,R_3R.BinStatRwrd{SortBin+1,1}.R1Mean); %suc responses
  283. MalResp=cat(1,R_3R.BinStatRwrd{SortBin+1,1}.R2Mean); %mal responses
  284. WatResp=cat(1,R_3R.BinStatRwrd{SortBin+1,1}.R3Mean); %wat responses
  285. [~,R_3R.RewRespStat{1,1},R_3R.RewRespStat{1,2}]=anovan(cat(1,SucResp(Sel),MalResp(Sel),WatResp(Sel)),{cat(1,zeros(sum(Sel),1),ones(sum(Sel),1),2*ones(sum(Sel),1)),cat(1,R_3R.Ninfo(Sel,4),R_3R.Ninfo(Sel,4),R_3R.Ninfo(Sel,4))},'varnames',{'Reward','Subject'},'random',2,'Display','off','model','full');
  286. R_3R.RewRespStat{1,3}=multcompare(R_3R.RewRespStat{1,2},'display','off');
  287. save('R_3R.mat','R_3R');