j_Fig5Water.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. clear all;
  2. load ('R_W.mat');
  3. load ('RAW.mat');
  4. %get parameters
  5. BinBase=R_W.Param.BinBase;
  6. BinDura=R_W.Param.BinDura;
  7. bins=R_W.Param.bins;
  8. binint=R_W.Param.binint;
  9. binstart=R_W.Param.binstart;
  10. PStatBins=0.01; %using more stringent cutoff to reduce pre-delivery noise
  11. %which bins bound the area examined for reward-selectivity? (in seconds)
  12. Time1=0.4; %seconds
  13. Time2=3; %seconds
  14. Bin1=(((Time1-BinDura(2)/2)-binstart)/binint); %convert to bin name
  15. Bin2=(((Time2-BinDura(2)/2)-binstart)/binint); %convert to bin name
  16. %sorting bin -- which bin the neurons' activity is sorted on for heatmap(in seconds)
  17. SortBinTime=1; %seconds
  18. SortBin=round((((SortBinTime-BinDura(2)/2)-binstart)/binint)); %convert to bin name
  19. sucrose=[1 0.6 0.1];
  20. maltodextrin=[.9 0.3 .9];
  21. water=[0.00 0.75 0.75];
  22. total=[0.3 0.1 0.8];
  23. exc=[0 113/255 188/255];
  24. inh=[240/255 0 50/255];
  25. %% bins analysis
  26. %first and last bin aren't included because you can't compare to the previous/subsequent bin
  27. %this axis plots the bins on their centers
  28. xaxis=linspace(binstart+binint+BinDura(2)/2,binstart+(bins-2)*binint+BinDura(2)/2,bins-2);
  29. for i=2:(bins-1) %no including first or last bin because can't compare to previous/subsequent bin
  30. %finds out whether firing is stronger (high excitation or lower inhibition) for 1 or 2
  31. for k=1:length(R_W.Ninfo) %runs through neurons
  32. if R_W.BinStatRwrd{i,1}(k).IntSig < PStatBins %if neuron is significant for this bin
  33. if R_W.BinStatRwrd{i-1,1}(k).IntSig < PStatBins || R_W.BinStatRwrd{i+1,1}(k).IntSig < PStatBins %either previous or subsequent bin must be significant
  34. if R_W.BinStatRwrd{i,1}(k).R1Mean > R_W.BinStatRwrd{i,1}(k).R2Mean %if firing is greater on sucrose trials than maltodextrin
  35. R_W.BinRewPref{i,1}(k,1)=1;
  36. else
  37. R_W.BinRewPref{i,1}(k,1)=2; %otherwise maltodextrin must be greater than sucrose
  38. end
  39. else
  40. R_W.BinRewPref{i,1}(k,1)=0; %if not significant in 2 consecutive bins
  41. end
  42. else
  43. R_W.BinRewPref{i,1}(k,1)=0; %if no sig reward modulation
  44. end
  45. end
  46. %find how many NAc neurons have significant reward modulation in each bin
  47. NN1perBin(i,1)=sum(R_W.BinRewPref{i,1}(:,1)==1); %sucrose pref
  48. NN2perBin(i,1)=sum(R_W.BinRewPref{i,1}(:,1)==2); %malto pref
  49. NNperBin(i,1)=sum(R_W.BinRewPref{i,1}(:,1)>0); %either
  50. %normalize to number of neurons in population
  51. NN1norm=NN1perBin./sum(length(R_W.Ninfo));
  52. NN2norm=NN2perBin./sum(length(R_W.Ninfo));
  53. NNnorm=NNperBin./sum(length(R_W.Ninfo));
  54. end
  55. %Cumulative reward selectivity
  56. cumsel=zeros(length(R_W.Ninfo),bins); %set up result matrix
  57. cumsel1=zeros(length(R_W.Ninfo),bins); %set up result matrix for sucrose
  58. cumsel2=zeros(length(R_W.Ninfo),bins); %set up result matrix for maltodextrin
  59. %note, this has to be corrected to +1 because of the way the bin matrix is
  60. %layed out (bin 0 is the first column, not the 0th column)
  61. for i=1:length(R_W.Ninfo) %go through each neuron
  62. for j=2:bins-1 %look in each bin we did analysis on
  63. if R_W.BinRewPref{j,1}(i,1)>0 || cumsel(i,j-1)==1
  64. cumsel(i,j) = 1;
  65. end
  66. if R_W.BinRewPref{j,1}(i,1)==1 || cumsel1(i,j-1)==1
  67. cumsel1(i,j) = 1;
  68. end
  69. if R_W.BinRewPref{j,1}(i,1)==2 || cumsel2(i,j-1)==1
  70. cumsel2(i,j) = 1;
  71. end
  72. end
  73. end
  74. %plotting number of significantly modulated neurons across time
  75. subplot(3,2,2);
  76. hold on;
  77. plot(xaxis,NNnorm(2:bins-1),'Color', total,'linewidth',1.5);
  78. plot(xaxis,NN1norm(2:bins-1),'Color',water,'linewidth',1.5);
  79. plot(xaxis,NN2norm(2:bins-1),'Color',maltodextrin,'linewidth',1.5);
  80. plot([Time1 Time1],[-1 1],':','color','k','linewidth',0.75);
  81. plot([Time2 Time2],[-1 1],':','color','k','linewidth',0.75);
  82. axis([xaxis(1) xaxis(end) 0 0.7]);
  83. legend('Total','Wat > mal','Mal > wat','Location','northeast')
  84. ylabel('Fraction of population');
  85. title('Reward-selective neurons');
  86. xlabel('Seconds from RD');
  87. %% plotting maltodextrin-selective neurons
  88. %color map
  89. [magma,inferno,plasma,viridis]=colormaps;
  90. colormap(plasma);
  91. c=[-100 2000];ClimE=sign(c).*abs(c).^(1/4);%colormap
  92. %events we're looking at
  93. ev1=strcmp('RD1', R_W.Erefnames);
  94. ev2=strcmp('RD2', R_W.Erefnames);
  95. %setting up parameters
  96. Xaxis=[-2 5];
  97. inttime=find(R_W.Param.Tm>=Xaxis(1) & R_W.Param.Tm<=Xaxis(2));
  98. paramtime=R_W.Param.Tm(inttime);
  99. %find all neurons with greater firing for maltodextrin
  100. for i = 1:(Bin2-Bin1+1)
  101. %the added +1 is necessary because bin 20 is the 21st entry in the matrix
  102. Pref1(:,i)=R_W.BinRewPref{Bin1+i}==2; %get neurons that have greater firing for water in any of the bins bounded above
  103. Resp11(:,i)=Pref1(:,i)&cat(1,R_W.BinStatRwrd{Bin1+i,1}.WatRespDir)==-1; %get neurons with inhibition to water
  104. Resp12(:,i)=Pref1(:,i)&cat(1,R_W.BinStatRwrd{Bin1+i,1}.MalRespDir)==1;%get neurons with excitation to maltodextrin
  105. end
  106. Mel=sum(Pref1,2)>0; %all neurons selective for mal in any bin
  107. Mel2=sum(Resp11,2)>0; %all selective neurons water inhibited in any bin
  108. Mel3=sum(Resp12,2)>0; %all selective neurons malto excited in any bin
  109. subplot(9,40,[(15:23)+120 (15:23)+160]); %heatmap of maltodextrin preferring neurons' response to water
  110. Neurons=R_W.Ev(ev1).PSTHz(Mel,inttime); %get the firing rates of neurons of interest
  111. MalResp=cat(1,R_W.BinStatRwrd{SortBin+1,1}.R2Mean); %water responses
  112. TMP=MalResp(Mel); %find the magnitude of the excitations for water for this bin
  113. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  114. [~,SORTimg]=sort(TMP);
  115. Neurons=Neurons(SORTimg,:); %sort the neurons by magnitude
  116. imagesc(paramtime,[1,sum(Mel,1)],Neurons,ClimE);
  117. title(['Water trials']);
  118. ylabel('Individual neurons');
  119. hold on;
  120. plot([0 0],[0 sum(Mel)],':','color','k','linewidth',0.75);
  121. subplot(9,40,[(27:35)+120 (27:35)+160]); %heatmap of maltodextrin preferring neurons' response to maltodextrin
  122. Neurons=R_W.Ev(ev2).PSTHz(Mel,inttime); %get the firing rates of neurons of interest
  123. Neurons=Neurons(SORTimg,:); %sort the neurons same as before
  124. imagesc(paramtime,[1,sum(Mel,1)],Neurons,ClimE);
  125. title(['Maltodextrin trials']);
  126. xlabel('Seconds from RD');
  127. hold on;
  128. plot([0 0],[0 sum(Mel)],':','color','k','linewidth',0.75);
  129. %plot water preferring neurons to water
  130. psth1=nanmean(R_W.Ev(ev1).PSTHz(Mel,inttime),1);
  131. sem1=nanste(R_W.Ev(ev1).PSTHz(Mel,inttime),1); %calculate standard error of the mean
  132. up1=psth1+sem1;
  133. down1=psth1-sem1;
  134. %plot water preferring neurons to malt
  135. psth2=nanmean(R_W.Ev(ev2).PSTHz(Mel,inttime),1);
  136. sem2=nanste(R_W.Ev(ev2).PSTHz(Mel,inttime),1); %calculate standard error of the mean
  137. up2=psth2+sem2;
  138. down2=psth2-sem2;
  139. %plotting
  140. subplot(9,3,[10 13]);
  141. title(['Mal>wat (n=' num2str(sum(Mel)) ' of ' num2str(length(Mel)) ')'])
  142. hold on;
  143. plot(paramtime,psth1,'Color',water,'linewidth',1);
  144. plot(paramtime,psth2,'Color',maltodextrin,'linewidth',1);
  145. patch([paramtime,paramtime(end:-1:1)],[up1,down1(end:-1:1)],water,'EdgeColor','none');alpha(0.5);
  146. patch([paramtime,paramtime(end:-1:1)],[up2,down2(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  147. plot([-2 5],[0 0],':','color','k','linewidth',0.75);
  148. plot([0 0],[-2 10],':','color','k','linewidth',0.75);
  149. axis([-2 5 -1.5 3.5]);
  150. ylabel('Mean firing (z-score)');
  151. legend('Wat trials','Mal trials');
  152. xlabel('Seconds from RD');
  153. %display inhibitions and excitations
  154. both = sum(Mel2&Mel3);
  155. excite = sum(Mel3)-both;
  156. inhib = sum(Mel2)-both;
  157. subplot(9,40,[160 200]);
  158. b = bar([inhib both excite; 0 0 0],'stacked');
  159. b(1,1).FaceColor=water;
  160. b(1,2).FaceColor=total;
  161. b(1,3).FaceColor=maltodextrin;
  162. axis([1 1.2 0 both+excite+inhib]);
  163. ylabel('Inh / Both / Excited');
  164. set(gca,'xtick',[])
  165. %% emergence of maltodextrin and water responses
  166. %select which time point we're examining
  167. Window=[0.8 1.8]; %For looking at emergence of excitation
  168. NN=0; %neuron counter
  169. Sess=0; %session counter
  170. %plotting
  171. sucrose=[1 0.6 0.1];
  172. maltodextrin=[.9 0.3 .9];
  173. water=[0.00 0.75 0.75];
  174. total=[0.3 0.1 0.8];
  175. exc=[0 113/255 188/255];
  176. inh=[240/255 0 50/255];
  177. %get firing rates on each trial
  178. for i=1:length(RAW) %loops through sessions
  179. if strcmp('WA',RAW(i).Type(1:2))
  180. Sess=Sess+1; %session counter
  181. SN{Sess}=0; %selective neuron counter
  182. ev1=strmatch('RD1',RAW(i).Einfo(:,2),'exact');
  183. ev2=strmatch('RD2',RAW(i).Einfo(:,2),'exact');
  184. for j= 1:size(RAW(i).Nrast,1) %Number of neurons within sessions
  185. NN=NN+1;
  186. if Mel(NN)==1
  187. SN{Sess}=SN{Sess}+1;
  188. Bcell1=0;
  189. Bcell2=0;
  190. Bcell=0;
  191. ev1spk=0;
  192. Ev2spk=0;
  193. %get mean baseline firing for all reward trials
  194. [Bcell1,B1n]=MakePSR04(RAW(i).Nrast(j),RAW(i).Erast{ev1},BinBase,{2});% makes trial by trial rasters for baseline
  195. for y= 1:B1n
  196. Bcell(1,y)=sum(Bcell1{1,y}>BinBase(1));
  197. end
  198. [Bcell2,B2n]=MakePSR04(RAW(i).Nrast(j),RAW(i).Erast{ev2},BinBase,{2});% makes trial by trial rasters for baseline
  199. for z= 1:B2n
  200. Bcell(1,z+B1n)=sum(Bcell2{1,z}>BinBase(1));
  201. end
  202. Bhz=Bcell/(BinBase(1,2)-BinBase(1,1));
  203. Bmean=nanmean(Bhz);
  204. Bstd=nanstd(Bhz);
  205. %get trial by trial firing rate for water trials
  206. [ev1cell,ev1n]=MakePSR04(RAW(i).Nrast(j),RAW(i).Erast{ev1},Window,{2});% makes trial by trial rasters for event
  207. for y= 1:ev1n
  208. ev1spk(SN{Sess},y)=sum(ev1cell{1,y}>Window(1));
  209. end
  210. ev1hz=ev1spk(SN{Sess},:)/(Window(1,2)-Window(1,1));
  211. for x= 1:ev1n
  212. ev1norm{Sess}(SN{Sess},x)=((ev1hz(1,x)-Bmean)/Bstd);
  213. end
  214. %get trial by trial firing rate for maltodextrin trials
  215. [ev2cell,ev2n]=MakePSR04(RAW(i).Nrast(j),RAW(i).Erast{ev2},Window,{2});% makes trial by trial rasters for event
  216. for y= 1:ev2n
  217. ev2spk(1,y)=sum(ev2cell{1,y}>Window(1));
  218. end
  219. ev2hz=ev2spk/(Window(1,2)-Window(1,1));
  220. for x= 1:ev2n
  221. ev2norm{Sess}(SN{Sess},x)=((ev2hz(1,x)-Bmean)/Bstd);
  222. end
  223. end
  224. end %neurons in each session
  225. trialmeanz1{Sess}=NaN(2,1);
  226. trialmeanz2{Sess}=NaN(2,1);
  227. ind=0;
  228. order=0;
  229. [~,ind]=sort(cat(1,RAW(i).Erast{ev1},RAW(i).Erast{ev2}));
  230. for j=1:length(ind)
  231. order(j,1)=find(ind==j);
  232. end
  233. xaxis1{Sess}=order(1:length(ev1norm{Sess}(1,:)));
  234. xaxis2{Sess}=order(1+length(ev1norm{Sess}(1,:)):end);
  235. for k=1:length(ev1norm{Sess}(1,:))
  236. trialmeanz1{Sess}(1,k)=nanmean(ev1norm{Sess}(:,k));
  237. trialmeanz1{Sess}(2,k)=nanste(ev1norm{Sess}(:,k),1);
  238. end
  239. for k=1:length(ev2norm{Sess}(1,:))
  240. trialmeanz2{Sess}(1,k)=nanmean(ev2norm{Sess}(:,k));
  241. trialmeanz2{Sess}(2,k)=nanste(ev2norm{Sess}(:,k),1);
  242. end
  243. %stats checking for interaction between # of reward presentations
  244. %and reward on firing rate
  245. numtrials=min([length(xaxis1{Sess}) length(xaxis2{Sess})]); %number of trials for stats (fewest number of trials for the 2 outcomes)
  246. trials1=repmat(1:numtrials,length(ev1norm{Sess}(:,1)),1);
  247. trials2=repmat(1:numtrials,length(ev2norm{Sess}(:,1)),1);
  248. reward1=zeros(size(trials1));
  249. reward2=ones(size(trials2));
  250. data1=ev1norm{Sess}(:,1:numtrials);
  251. data2=ev2norm{Sess}(:,1:numtrials);
  252. [~,R_W.EmergenceStats{Sess,1},R_W.EmergenceStats{Sess,2}]=anovan(cat(1,data1(:),data2(:)),{cat(1,trials1(:),trials2(:)),cat(1,reward1(:),reward2(:))},'varnames',{'trials','reward'},'display','off','model','full');
  253. end %checking if a water session
  254. end %session
  255. %plotting
  256. for i=1:Sess
  257. subplot(3,2,4+i);
  258. hold on;
  259. errorbar(xaxis1{i},trialmeanz1{i}(1,:),trialmeanz1{i}(2,:),'*','Color',water,'linewidth',1.5);
  260. errorbar(xaxis2{i},trialmeanz2{i}(1,:),trialmeanz2{i}(2,:),'*','Color',maltodextrin,'linewidth',1.5);
  261. %plot(xaxis1,(cell2mat(ev1stat{i}(1,:))*13-16.9),'*','Color',water); %(12.5-trialmeanz242(1,1:trials1)-trialmeanz242(2,1:trials1))
  262. %plot(xaxis2,(cell2mat(ev2stat{i}(1,:))*13-16.7),'*','Color',maltodextrin); %(12.5-trialmeanz242(1,1:trials1)-trialmeanz242(2,1:trials1))
  263. %plot(xaxis1,(cell2mat(trialstat42(1,1:trials1))*13-17.1),'*','Color','k'); %(12.5-trialmeanz242(1,1:trials1)-trialmeanz242(2,1:trials1))
  264. plot([0 60],[0 0],':','color','k','linewidth',0.75);
  265. ylabel(['Mean firing ' num2str(Window(1,1)) '-' num2str(Window(1,2)) 's (z-score)']);
  266. title(['Rat ' num2str(i) ' (n=' num2str(SN{i}) ')']);
  267. axis([1 max([xaxis1{i};xaxis2{i}]) min(trialmeanz1{i}(1,:))*1.3 max(trialmeanz2{i}(1,:))*1.3]);
  268. xlabel('Trial #');
  269. legend('Wat','Mal','location','northwest');
  270. end
  271. %% conduct lick analysis
  272. global Dura Tm BSIZE Tbin
  273. path='C:\Users\dottenh2\Documents\MATLAB\David\2Rewards Nex Files\2RLick_paper.xls';
  274. %Main settings
  275. BSIZE=0.01; %Do not change
  276. Dura=[-22 20]; Tm=Dura(1):BSIZE:Dura(2);
  277. Tbin=-0.5:0.005:0.5; %window used to determine the optimal binsize
  278. MinNumTrials=5;
  279. Lick=[];Lick.Ninfo={};LL=0;Nlick=0;
  280. %Smoothing
  281. Smoothing=1; %0 for raw and 1 for smoothing
  282. SmoothTYPE='lowess'; %can change this between lowess and rlowess (more robust, ignores outliers more)
  283. SmoothSPAN=50; %percentage of total data points
  284. if Smoothing~=1, SmoothTYPE='NoSmoothing';SmoothSPAN=NaN; end
  285. % List of events to analyze and analysis windows EXTRACTED from excel file
  286. [~,Erefnames]=xlsread(path,'Windows','a3:a10'); % cell that contains the event names
  287. %Finds the total number of sessions
  288. for i=1:length(RAW)
  289. if strcmp('WA',RAW(i).Type(1:2))
  290. Nlick=Nlick+1;
  291. Lick.Linfo(i,1)=RAW(i).Ninfo(1,1);
  292. end
  293. end
  294. Lick.Erefnames= Erefnames;
  295. %preallocating the result matrix
  296. for k=1:length(Erefnames)
  297. Lick.Ev(k).PSTHraw(1:Nlick,1:length(Tm))=NaN(Nlick,length(Tm));
  298. Lick.Ev(k).BW(1:Nlick,1)=NaN;
  299. Lick.Ev(k).NumberTrials(1:Nlick,1)=NaN;
  300. end
  301. for i=1:length(RAW) %loops through sessions
  302. if strcmp('WA',RAW(i).Type(1:2))
  303. LL=LL+1; %lick session counter
  304. for k=1:length(Erefnames) %loops thorough the events
  305. EvInd=strcmp(Erefnames(k),RAW(i).Einfo(:,2)); %find the event id number from RAW
  306. LickInd=strcmp('Licks',RAW(i).Einfo(:,2)); %find the event id number from RAW
  307. if sum(EvInd)==0
  308. fprintf('HOWDY, CANT FIND EVENTS FOR ''%s''\n',Erefnames{k});
  309. end
  310. Lick.Ev(k).NumberTrials(LL,1)=length(RAW(i).Erast{EvInd});
  311. if ~isempty(EvInd) && Lick.Ev(k).NumberTrials(LL,1)>MinNumTrials %avoid analyzing sessions where that do not have enough trials
  312. [PSR1,N1]=MakePSR04(RAW(i).Erast(LickInd),RAW(i).Erast{EvInd},Dura,{1});% makes collpased rasters. PSR1 is a cell(neurons)
  313. if ~isempty(PSR1{1}) %to avoid errors, added on 12/28 2011
  314. %forcing 100ms bin size to keep it consistent across
  315. %sessions (no reason is should be different for licks)
  316. [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
  317. PTH1=smooth(PTH1,SmoothSPAN,SmoothTYPE)';
  318. %------------- Fills the R.Ev(k) fields --------------
  319. Lick.Ev(k).BW(LL,1)=BW1;
  320. Lick.Ev(k).PSTHraw(LL,1:length(Tm))=PTH1;
  321. end
  322. end
  323. end
  324. end
  325. end
  326. Xaxis=[-2 12];
  327. Ishow=find(Tm>=Xaxis(1) & Tm<=Xaxis(2));
  328. time1=Tm(Ishow);
  329. c=[-1000 7500];ClimE=sign(c).*abs(c).^(1/4);%ColorMapExc
  330. colormap(jet);
  331. sucrose=[1 0.6 0.1];
  332. maltodextrin=[.9 0.3 .9];
  333. water=[0.00 0.75 0.75];
  334. total=[0.3 0.1 0.8];
  335. exc=[0 113/255 188/255];
  336. inh=[240/255 0 50/255];
  337. Ev1=strcmp('RD1', Lick.Erefnames);
  338. Ev2=strcmp('RD2', Lick.Erefnames);
  339. psth1=nanmean(Lick.Ev(Ev1).PSTHraw(:,Ishow),1);
  340. sem1=nanste(Lick.Ev(Ev1).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  341. up1=psth1+sem1;
  342. down1=psth1-sem1;
  343. psthE=nanmean(Lick.Ev(Ev2).PSTHraw(:,Ishow),1);
  344. semE=nanste(Lick.Ev(Ev2).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  345. upE=psthE+semE;
  346. downE=psthE-semE;
  347. %plotting
  348. subplot(3,2,1);
  349. hold on;
  350. plot(time1,psth1,'Color',water,'linewidth',1);
  351. plot(time1,psthE,'Color',maltodextrin,'linewidth',1);
  352. patch([time1,time1(end:-1:1)],[up1,down1(end:-1:1)],water,'EdgeColor','none');alpha(0.5);
  353. patch([time1,time1(end:-1:1)],[upE,downE(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  354. title('Mean lick rate');
  355. %plot([-2 10],[0 0],':','color','k');
  356. plot([0 0],[-2 8],':','color','k','linewidth',0.75);
  357. axis([-2 12 0 7.5]);
  358. xlabel('Seconds from reward delivery');
  359. ylabel('Licks/s');
  360. legend('Water trials','Maltodextrin trials');
  361. %color map
  362. [magma,inferno,plasma,viridis]=colormaps;
  363. colormap(plasma);
  364. c=[-100 2000];ClimE=sign(c).*abs(c).^(1/4);%colormap
  365. %% creating and saving new variables
  366. R_W.MalN=Mel;
  367. % proportion summary and chi squared test for reward selective neurons in
  368. % sucrose and water sessions in VP
  369. %find all reward-selective neurons
  370. for i = 1:(Bin2-Bin1+1)
  371. %the added +1 is necessary because bin 20 is the 21st entry in the matrix
  372. Selective(:,i)=R_W.BinRewPref{Bin1+i}>0; %get neurons that have greater firing for water in any of the bins bounded above
  373. end
  374. WSel=sum(Pref1,2)>0; %all neurons selective for mal in any bin
  375. %get reward selective neurons from these two rats
  376. load ('R_2R.mat');
  377. selection=(R_2R.SucN | R_2R.MalN); %selective neurons in suc vs mal sessions
  378. SSel=selection(strcmp('VP2',R_2R.Ninfo(:,4)) | strcmp('VP5',R_2R.Ninfo(:,4)),1);
  379. %get proportion and stats
  380. R_W.SucvsWatX2(1,1)=sum(SSel)/length(SSel); %selective neurons in maltodextrin sessions
  381. R_W.SucvsWatX2(1,2)=sum(WSel)/length(WSel); %how many selective neurons in water sessions
  382. [~,R_W.SucvsWatX2(2,1),R_W.SucvsWatX2(2,2)]=crosstab(cat(1,SSel,WSel),cat(1,ones(length(SSel),1),zeros(length(WSel),1))); %find chi squared value for this distribution
  383. save('R_W.mat','R_W');