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.

c_Fig1Behavior.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. %this program analyzes behavior and puts it in the Lick struct
  2. %can change what it's saved as here to later compare Int and Blocks
  3. clear all;
  4. load ('RAW.mat');
  5. load ('R_2R.mat');
  6. %which lick intervals to look at?
  7. startinterval=1;
  8. endinterval=30;
  9. %time to look at difference in licking activity
  10. earlylicks=[1 4.5];
  11. %% conduct lick analysis
  12. global Dura Tm BSIZE Tbin
  13. tic
  14. path='C:\Users\dottenh2\Documents\MATLAB\David\2Rewards Nex Files\2RLick_paper.xls';
  15. if ~exist('RAW'), load ('RAW.mat'); end
  16. %Main settings
  17. BSIZE=0.01; %Do not change
  18. Dura=[-22 20]; Tm=Dura(1):BSIZE:Dura(2);
  19. Tbin=-0.5:0.005:0.5; %window used to determine the optimal binsize
  20. MinNumTrials=5;
  21. Lick=[];Lick.Ninfo={};LL=0;NSess=0;
  22. %Smoothing
  23. Smoothing=1; %0 for raw and 1 for smoothing
  24. SmoothTYPE='lowess'; %can change this between lowess and rlowess (more robust, ignores outliers more)
  25. SmoothSPAN=50; %percentage of total data points
  26. if Smoothing~=1, SmoothTYPE='NoSmoothing';SmoothSPAN=NaN; end
  27. % List of events to analyze and analysis windows EXTRACTED from excel file
  28. [~,Erefnames]=xlsread(path,'Windows','a3:a10'); % cell that contains the event names
  29. %Finds the total number of suc vs mal sessions
  30. for i=1:length(RAW)
  31. if strcmp('NA',RAW(i).Type(1:2)) | strcmp('VP',RAW(i).Type(1:2))
  32. NSess=NSess+1;
  33. Lick.Linfo(i,1)=RAW(i).Ninfo(1,1);
  34. end
  35. end
  36. Lick.Erefnames= Erefnames;
  37. %preallocating for behavior stats
  38. Lick.RewDurR1=NaN(NSess,35);
  39. Lick.RewDurR2=NaN(NSess,35);
  40. Lick.NumLicksR1=NaN(NSess,35);
  41. Lick.NumLicksR2=NaN(NSess,35);
  42. Lick.LicksEarlyR1=NaN(NSess,35);
  43. Lick.LicksEarlyR2=NaN(NSess,35);
  44. Lick.LicksR1P1=NaN(NSess,35);
  45. Lick.LicksR1P2=NaN(NSess,35);
  46. Lick.LicksR2P1=NaN(NSess,35);
  47. Lick.LicksR2P2=NaN(NSess,35);
  48. for i=1:endinterval
  49. Lick.ILIR1{i,1}=NaN(NSess,35);
  50. Lick.ILIR2{i,1}=NaN(NSess,35);
  51. end
  52. %preallocating the result matrix
  53. for k=1:length(Erefnames)
  54. Lick.Ev(k).PSTHraw(1:NSess,1:length(Tm))=NaN(NSess,length(Tm));
  55. Lick.Ev(k).BW(1:NSess,1)=NaN;
  56. Lick.Ev(k).NumberTrials(1:NSess,1)=NaN;
  57. end
  58. for i=1:length(RAW) %loops through sessions
  59. if strcmp('NA',RAW(i).Type(1:2)) | strcmp('VP',RAW(i).Type(1:2))
  60. LL=LL+1; %lick session counter
  61. for k=1:length(Erefnames) %loops thorough the events
  62. EvInd=strcmp(Erefnames(k),RAW(i).Einfo(:,2)); %find the event id number from RAW
  63. LickInd=strcmp('Licks',RAW(i).Einfo(:,2)); %find the event id number from RAW
  64. if sum(EvInd)==0
  65. fprintf('HOWDY, CANT FIND EVENTS FOR ''%s''\n',Erefnames{k});
  66. end
  67. Lick.Ev(k).NumberTrials(LL,1)=length(RAW(i).Erast{EvInd});
  68. if ~isempty(EvInd) && Lick.Ev(k).NumberTrials(LL,1)>MinNumTrials %avoid analyzing sessions where that do not have enough trials
  69. [PSR1,N1]=MakePSR04(RAW(i).Erast(LickInd),RAW(i).Erast{EvInd},Dura,{1});% makes collpased rasters. PSR1 is a cell(neurons)
  70. if ~isempty(PSR1{1}) %to avoid errors, added on 12/28 2011
  71. %forcing 100ms bin size to keep it consistent across
  72. %sessions (no reason is should be different for licks)
  73. [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
  74. PTH1=smooth(PTH1,SmoothSPAN,SmoothTYPE)';
  75. %------------- Fills the R.Ev(k) fields --------------
  76. Lick.Ev(k).BW(LL,1)=BW1;
  77. Lick.Ev(k).PSTHraw(LL,1:length(Tm))=PTH1;
  78. end
  79. end
  80. end
  81. %% this section finds the ILIs, number of licks, and lick duration
  82. RD1=strmatch('RD1',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  83. RD2=strmatch('RD2',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  84. RD1P1=strmatch('RD1P1',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  85. RD1P2=strmatch('RD1P2',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  86. RD2P1=strmatch('RD2P1',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  87. RD2P2=strmatch('RD2P2',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  88. Rind=strmatch('BoutEndRLast',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  89. Lind=strmatch('Licks',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  90. %trying to make the ISI calculator Peter recommended
  91. %unfortunately, there's one trial of maltodextrin with only one
  92. %lick
  93. %so I need to put this lame code in to avoid an error
  94. % NL2{1,4}=NaN(40,1);
  95. %except it doesn't work!
  96. %find durations of reward consumption for all, R1, and R2 trls
  97. RDu1=MakePSR04(RAW(i).Erast(Rind),RAW(i).Erast{RD1},[0 15],{2,'first'});
  98. RDu2=MakePSR04(RAW(i).Erast(Rind),RAW(i).Erast{RD2},[0 15],{2,'first'});
  99. Lick.RewDurR1(LL,1:length(RDu1))=cell2mat(RDu1);
  100. Lick.RewDurR2(LL,1:length(RDu2))=cell2mat(RDu2);
  101. %find number of licks for all, R1, and R2 trls
  102. NL1=MakePSR04(RAW(i).Erast(Lind),RAW(i).Erast{RD1},[0 15],{2});
  103. NL2=MakePSR04(RAW(i).Erast(Lind),RAW(i).Erast{RD2},[0 15],{2});
  104. %find number of licks in 1-3 seconds post-reward
  105. EL1=MakePSR04(RAW(i).Erast(Lind),RAW(i).Erast{RD1},[earlylicks(1) earlylicks(2)],{2});
  106. EL2=MakePSR04(RAW(i).Erast(Lind),RAW(i).Erast{RD2},[earlylicks(1) earlylicks(2)],{2});
  107. %break that down by previous reward
  108. NL1P1=MakePSR04(RAW(i).Erast(Lind),RAW(i).Erast{RD1P1},[earlylicks(1) earlylicks(2)],{2});
  109. NL1P2=MakePSR04(RAW(i).Erast(Lind),RAW(i).Erast{RD1P2},[earlylicks(1) earlylicks(2)],{2});
  110. NL2P1=MakePSR04(RAW(i).Erast(Lind),RAW(i).Erast{RD2P1},[earlylicks(1) earlylicks(2)],{2});
  111. NL2P2=MakePSR04(RAW(i).Erast(Lind),RAW(i).Erast{RD2P2},[earlylicks(1) earlylicks(2)],{2});
  112. %make lick matrices
  113. for j=1:length(NL1)
  114. Lick.NumLicksR1(LL,j)=sum(NL1{1,j}>0);
  115. Lick.LicksEarlyR1(LL,j)=sum(EL1{1,j}>0);
  116. for k=startinterval:endinterval
  117. if length(NL1{1,j})>k
  118. Lick.ILIR1{k,1}(LL,j)= NL1{1,j}(k+1,1)-NL1{1,j}(k,1);
  119. else
  120. Lick.ILIR1{k,1}(LL,j)= NaN;
  121. end
  122. end
  123. end
  124. for j=1:length(NL2)
  125. Lick.NumLicksR2(LL,j)=sum(NL2{1,j}>0);
  126. Lick.LicksEarlyR2(LL,j)=sum(EL2{1,j}>0);
  127. for k=startinterval:endinterval
  128. if length(NL2{1,j})>k
  129. Lick.ILIR2{k,1}(LL,j)= NL2{1,j}(k+1,1)-NL2{1,j}(k,1);
  130. else
  131. Lick.ILIR2{k,1}(LL,j)= NaN;
  132. end
  133. end
  134. end
  135. %now for the previous reward situation
  136. for j=1:length(NL1P1)
  137. Lick.LicksR1P1(LL,j)=sum(NL1P1{1,j}>0);
  138. end
  139. for j=1:length(NL1P2)
  140. Lick.LicksR1P2(LL,j)=sum(NL1P2{1,j}>0);
  141. end
  142. for j=1:length(NL2P1)
  143. Lick.LicksR2P1(LL,j)=sum(NL2P1{1,j}>0);
  144. end
  145. for j=1:length(NL2P2)
  146. Lick.LicksR2P2(LL,j)=sum(NL2P2{1,j}>0);
  147. end
  148. %get session and rat #
  149. Lick.Sess(LL,1:35)=i;
  150. A=char(RAW(i).Ninfo(1,1));
  151. Lick.Rat(LL,1:35)=cellstr(A(1:3));
  152. fprintf('Session # %d\n',LL);
  153. end
  154. end
  155. %% computing stats
  156. %setting up result stat matrix
  157. R_2R.BehAvs{2,1}='RewDur';
  158. R_2R.BehAvs{3,1}='NumLicks';
  159. R_2R.BehAvs{4,1}='NumLicksEarly';
  160. R_2R.BehAvs{1,2}='R1 Avg';
  161. R_2R.BehAvs{1,3}='R2 Avg';
  162. %putting all values into one row array and removing NaN, doing 3-way ANOVA
  163. %with fixed effect of reward and random effects of session nested in rat
  164. %reward duration
  165. Lick.RDR1=reshape(Lick.RewDurR1,1,numel(Lick.RewDurR1));
  166. Lick.RDR1Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  167. Lick.RDR1Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  168. Lick.RDR1Sess(isnan(Lick.RDR1))=[];
  169. Lick.RDR1Rat(isnan(Lick.RDR1))=[];
  170. Lick.RDR1(isnan(Lick.RDR1))=[];
  171. Lick.RDR2=reshape(Lick.RewDurR2,1,numel(Lick.RewDurR2));
  172. Lick.RDR2Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  173. Lick.RDR2Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  174. Lick.RDR2Sess(isnan(Lick.RDR2))=[];
  175. Lick.RDR2Rat(isnan(Lick.RDR2))=[];
  176. Lick.RDR2(isnan(Lick.RDR2))=[];
  177. [~,R_2R.RDstats,~]=anovan(cat(2,Lick.RDR1,Lick.RDR2),{(cat(2,zeros(1,length(Lick.RDR1)),ones(1,length(Lick.RDR2)))),(cat(2,Lick.RDR1Sess,Lick.RDR2Sess)),(cat(2,Lick.RDR1Rat,Lick.RDR2Rat))},'varnames',{'reward','session','rat'},'nested',[0 0 0;0 0 1;0 0 0],'random',[2 3],'display','off','model','full'); %nested ANOVA
  178. %number of licks
  179. Lick.NLR1=reshape(Lick.NumLicksR1,1,numel(Lick.NumLicksR1));
  180. Lick.NLR1Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  181. Lick.NLR1Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  182. Lick.NLR1Sess(isnan(Lick.NLR1))=[];
  183. Lick.NLR1Rat(isnan(Lick.NLR1))=[];
  184. Lick.NLR1(isnan(Lick.NLR1))=[];
  185. Lick.NLR2=reshape(Lick.NumLicksR2,1,numel(Lick.NumLicksR2));
  186. Lick.NLR2Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  187. Lick.NLR2Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  188. Lick.NLR2Sess(isnan(Lick.NLR2))=[];
  189. Lick.NLR2Rat(isnan(Lick.NLR2))=[];
  190. Lick.NLR2(isnan(Lick.NLR2))=[];
  191. [~,R_2R.LicksStats,~]=anovan(cat(2,Lick.NLR1,Lick.NLR2),{(cat(2,zeros(1,length(Lick.NLR1)),ones(1,length(Lick.NLR2)))),(cat(2,Lick.NLR1Sess,Lick.NLR2Sess)),(cat(2,Lick.NLR1Rat,Lick.NLR2Rat))},'varnames',{'reward','session','rat'},'nested',[0 0 0;0 0 1;0 0 0],'random',[2 3],'display','off','model','full'); %nested ANOVA
  192. %number of licks 1-3sec
  193. Lick.ELR1=reshape(Lick.LicksEarlyR1,1,numel(Lick.LicksEarlyR1));
  194. Lick.ELR1Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  195. Lick.ELR1Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  196. Lick.ELR1Sess(isnan(Lick.ELR1))=[];
  197. Lick.ELR1Rat(isnan(Lick.ELR1))=[];
  198. Lick.ELR1(isnan(Lick.ELR1))=[];
  199. Lick.ELR2=reshape(Lick.LicksEarlyR2,1,numel(Lick.LicksEarlyR2));
  200. Lick.ELR2Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  201. Lick.ELR2Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  202. Lick.ELR2Sess(isnan(Lick.ELR2))=[];
  203. Lick.ELR2Rat(isnan(Lick.ELR2))=[];
  204. Lick.ELR2(isnan(Lick.ELR2))=[];
  205. [~,R_2R.LicksEarlyStats,~]=anovan(cat(2,Lick.ELR1,Lick.ELR2),{(cat(2,zeros(1,length(Lick.ELR1)),ones(1,length(Lick.ELR2)))),(cat(2,Lick.ELR1Sess,Lick.ELR2Sess)),(cat(2,Lick.ELR1Rat,Lick.ELR2Rat))},'varnames',{'reward','session','rat'},'nested',[0 0 0;0 0 1;0 0 0],'random',[2 3],'display','off','model','full'); %nested ANOVA
  206. %number of licks 1-3sec
  207. Lick.NLR1P1=reshape(Lick.LicksR1P1,1,numel(Lick.LicksR1P1));
  208. Lick.NLR1P1Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  209. Lick.NLR1P1Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  210. Lick.NLR1P1Sess(isnan(Lick.NLR1P1))=[];
  211. Lick.NLR1P1Rat(isnan(Lick.NLR1P1))=[];
  212. Lick.NLR1P1(isnan(Lick.NLR1P1))=[];
  213. Lick.NLR1P2=reshape(Lick.LicksR1P2,1,numel(Lick.LicksR1P2));
  214. Lick.NLR1P2Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  215. Lick.NLR1P2Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  216. Lick.NLR1P2Sess(isnan(Lick.NLR1P2))=[];
  217. Lick.NLR1P2Rat(isnan(Lick.NLR1P2))=[];
  218. Lick.NLR1P2(isnan(Lick.NLR1P2))=[];
  219. Lick.NLR2P1=reshape(Lick.LicksR2P1,1,numel(Lick.LicksR2P1));
  220. Lick.NLR2P1Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  221. Lick.NLR2P1Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  222. Lick.NLR2P1Sess(isnan(Lick.NLR2P1))=[];
  223. Lick.NLR2P1Rat(isnan(Lick.NLR2P1))=[];
  224. Lick.NLR2P1(isnan(Lick.NLR2P1))=[];
  225. Lick.NLR2P2=reshape(Lick.LicksR2P2,1,numel(Lick.LicksR2P2));
  226. Lick.NLR2P2Sess=reshape(Lick.Sess,1,numel(Lick.Sess));
  227. Lick.NLR2P2Rat=reshape(Lick.Rat,1,numel(Lick.Rat));
  228. Lick.NLR2P2Sess(isnan(Lick.NLR2P2))=[];
  229. Lick.NLR2P2Rat(isnan(Lick.NLR2P2))=[];
  230. Lick.NLR2P2(isnan(Lick.NLR2P2))=[];
  231. [~,R_2R.LicksPrevRewStats,stats]=anovan(cat(2,Lick.NLR1P1,Lick.NLR1P2,Lick.NLR2P1,Lick.NLR2P2),{cat(2,zeros(1,length(cat(2,Lick.NLR1P1,Lick.NLR1P2))),ones(1,length(cat(2,Lick.NLR2P1,Lick.NLR2P2)))),...
  232. cat(2,zeros(1,length(Lick.NLR1P1)),ones(1,length(Lick.NLR1P2)),zeros(1,length(Lick.NLR2P1)),ones(1,length(Lick.NLR2P2))),cat(2,Lick.NLR1P1Sess,Lick.NLR1P2Sess,Lick.NLR2P1Sess,Lick.NLR2P2Sess),...
  233. cat(2,Lick.NLR1P1Rat,Lick.NLR1P2Rat,Lick.NLR2P1Rat,Lick.NLR2P2Rat)},'varnames',{'current reward','prev reward','session','rat'},'nested',[0 0 0 0;0 0 0 0;0 0 0 1;0 0 0 0],'random',[3 4],'display','off','model','full'); %nested ANOVA
  234. % %without random factor of session
  235. % [~,R_2R.LicksPrevRewStats,stats]=anovan(cat(2,Lick.NLR1P1,Lick.NLR1P2,Lick.NLR2P1,Lick.NLR2P2),{cat(2,zeros(1,length(cat(2,Lick.NLR1P1,Lick.NLR1P2))),ones(1,length(cat(2,Lick.NLR2P1,Lick.NLR2P2)))),...
  236. % cat(2,zeros(1,length(Lick.NLR1P1)),ones(1,length(Lick.NLR1P2)),zeros(1,length(Lick.NLR2P1)),ones(1,length(Lick.NLR2P2))),...
  237. % cat(2,Lick.NLR1P1Rat,Lick.NLR1P2Rat,Lick.NLR2P1Rat,Lick.NLR2P2Rat)},'varnames',{'current reward','prev reward','rat'},'random',[3],'display','off','model','full');
  238. %ILI
  239. for m=startinterval:endinterval
  240. %first get session averages so I can do an ANOVA across all ILI
  241. Lick.ILIR1sessav{m,1}=nanmean(Lick.ILIR1{m,1},2);
  242. Lick.ILIR2sessav{m,1}=nanmean(Lick.ILIR2{m,1},2);
  243. Lick.ILIsesssess{m,1}=Lick.Sess(:,1);
  244. Lick.ILIsessrat{m,1}=Lick.Rat(:,1);
  245. %now do it with all trials
  246. Lick.ILIR1{m,1}=reshape(Lick.ILIR1{m,1},1,numel(Lick.ILIR1{m,1}));
  247. Lick.ILIR1Sess{m,1}=reshape(Lick.Sess,1,numel(Lick.ILIR1{m,1}));
  248. Lick.ILIR1Rat{m,1}=reshape(Lick.Rat,1,numel(Lick.ILIR1{m,1}));
  249. Lick.ILIR1Sess{m,1}(isnan(Lick.ILIR1{m,1}))=[];
  250. Lick.ILIR1Rat{m,1}(isnan(Lick.ILIR1{m,1}))=[];
  251. Lick.ILIR1{m,1}(isnan(Lick.ILIR1{m,1}))=[];
  252. Lick.ILIR2{m,1}=reshape(Lick.ILIR2{m,1},1,numel(Lick.ILIR2{m,1}));
  253. Lick.ILIR2Sess{m,1}=reshape(Lick.Sess,1,numel(Lick.ILIR2{m,1}));
  254. Lick.ILIR2Rat{m,1}=reshape(Lick.Rat,1,numel(Lick.ILIR2{m,1}));
  255. Lick.ILIR2Sess{m,1}(isnan(Lick.ILIR2{m,1}))=[];
  256. Lick.ILIR2Rat{m,1}(isnan(Lick.ILIR2{m,1}))=[];
  257. Lick.ILIR2{m,1}(isnan(Lick.ILIR2{m,1}))=[];
  258. end
  259. %getting effects of interval #, reward, rat, and session on ILI
  260. Lick.ILIR1all=[];
  261. Lick.ILIR1all=[];
  262. Lick.ILIR1Ratall=[];
  263. Lick.ILIR1Sessall=[];
  264. Lick.ILIR1Rewall=[];
  265. Lick.ILIR1Intall=[];
  266. Lick.ILIR2all=[];
  267. Lick.ILIR2all=[];
  268. Lick.ILIR2Ratall=[];
  269. Lick.ILIR2Sessall=[];
  270. Lick.ILIR2Rewall=[];
  271. Lick.ILIR2Intall=[];
  272. %to do session averages for comparing across all intervals
  273. for m=startinterval:endinterval
  274. Lick.ILIR1all=cat(1,Lick.ILIR1all,Lick.ILIR1sessav{m,1});
  275. Lick.ILIR1Ratall=cat(1,Lick.ILIR1Ratall,Lick.ILIsessrat{m,1});
  276. Lick.ILIR1Sessall=cat(1,Lick.ILIR1Sessall,Lick.ILIsesssess{m,1});
  277. Lick.ILIR1Rewall=cat(1,Lick.ILIR1Rewall,zeros(length(Lick.ILIR1sessav{m,1}),1));
  278. Lick.ILIR1Intall=cat(1,Lick.ILIR1Intall,(m*ones(length(Lick.ILIR1sessav{m,1}),1)));
  279. Lick.ILIR2all=cat(1,Lick.ILIR2all,Lick.ILIR2sessav{m,1});
  280. Lick.ILIR2Ratall=cat(1,Lick.ILIR2Ratall,Lick.ILIsessrat{m,1});
  281. Lick.ILIR2Sessall=cat(1,Lick.ILIR2Sessall,Lick.ILIsesssess{m,1});
  282. Lick.ILIR2Rewall=cat(1,Lick.ILIR2Rewall,ones(length(Lick.ILIR2sessav{m,1}),1));
  283. Lick.ILIR2Intall=cat(1,Lick.ILIR2Intall,(m*ones(length(Lick.ILIR2sessav{m,1}),1)));
  284. end
  285. %no factor of session
  286. [~,R_2R.ILItrialstats,~]=anovan(cat(1,Lick.ILIR1all,Lick.ILIR2all),{(cat(1,Lick.ILIR1Rewall,Lick.ILIR2Rewall)),(cat(1,Lick.ILIR1Ratall,Lick.ILIR2Ratall)),(cat(1,Lick.ILIR1Intall,Lick.ILIR2Intall))},'varnames',{'reward','rat','interval'},'random',[2],'display','off','model','full');
  287. %finding values for R_2R.BehAvs
  288. R_2R.BehAvs{2,2}=mean(Lick.RDR1);
  289. R_2R.BehAvs{2,3}=mean(Lick.RDR2);
  290. R_2R.BehAvs{3,2}=mean(Lick.NLR1);
  291. R_2R.BehAvs{3,3}=mean(Lick.NLR2);
  292. R_2R.BehAvs{4,2}=mean(Lick.ELR1);
  293. R_2R.BehAvs{4,3}=mean(Lick.ELR2);
  294. %Finding ILI
  295. for m=startinterval:endinterval
  296. Lick.ILI1(m,1)=nanmean(Lick.ILIR1{m,1}(:));
  297. Lick.ILI1(m,2)=nanstd(Lick.ILIR1{m,1}(:))/sqrt(sum(~isnan(Lick.ILIR1{m,1}(:))));
  298. Lick.ILI2(m,1)=nanmean(Lick.ILIR2{m,1}(:));
  299. Lick.ILI2(m,2)=nanstd(Lick.ILIR2{m,1}(:))/sqrt(sum(~isnan(Lick.ILIR2{m,1}(:))));
  300. end
  301. %% plotting licks in each reward condition
  302. Xaxis=[-2 12];
  303. Ishow=find(Tm>=Xaxis(1) & Tm<=Xaxis(2));
  304. time1=Tm(Ishow);
  305. c=[-1000 7500];ClimE=sign(c).*abs(c).^(1/4);%ColorMapExc
  306. colormap(jet);
  307. sucrose=[1 0.6 0.1];
  308. maltodextrin=[.9 0.3 .9];
  309. water=[0.00 0.75 0.75];
  310. total=[0.3 0.1 0.8];
  311. exc=[0 113/255 188/255];
  312. inh=[240/255 0 50/255];
  313. Ev1=strcmp('RD1', Lick.Erefnames);
  314. Ev2=strcmp('RD2', Lick.Erefnames);
  315. psth1=nanmean(Lick.Ev(Ev1).PSTHraw(:,Ishow),1);
  316. sem1=nanste(Lick.Ev(Ev1).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  317. up1=psth1+sem1;
  318. down1=psth1-sem1;
  319. psthE=nanmean(Lick.Ev(Ev2).PSTHraw(:,Ishow),1);
  320. semE=nanste(Lick.Ev(Ev2).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  321. upE=psthE+semE;
  322. downE=psthE-semE;
  323. %plotting
  324. subplot(2,2,1);
  325. hold on;
  326. plot(time1,psth1,'Color',sucrose,'linewidth',1);
  327. plot(time1,psthE,'Color',maltodextrin,'linewidth',1);
  328. patch([time1,time1(end:-1:1)],[up1,down1(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  329. patch([time1,time1(end:-1:1)],[upE,downE(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  330. title('Mean lick rate');
  331. %plot([-2 10],[0 0],':','color','k');
  332. plot([0 0],[-2 8],':','color','k','linewidth',0.75);
  333. plot([earlylicks(1) earlylicks(2)],[7.3 7.3],'color','k','linewidth',0.75);
  334. axis([-2 12 0 7.5]);
  335. xlabel('Seconds from reward delivery');
  336. ylabel('Licks/s');
  337. legend('Sucrose trials','Maltodextrin trials');
  338. %% plotting ILI
  339. sucrose=[1 0.6 0.1];
  340. maltodextrin=[.9 0.3 .9];
  341. water=[0.00 0.75 0.75];
  342. total=[0.3 0.1 0.8];
  343. exc=[0 113/255 188/255];
  344. inh=[240/255 0 50/255];
  345. xaxis=(startinterval:endinterval);
  346. subplot(2,2,3);
  347. hold on;
  348. errorbar(xaxis,Lick.ILI1(startinterval:endinterval,1),Lick.ILI1(startinterval:endinterval,2),'*','Color',sucrose,'linewidth',1.5);
  349. errorbar(xaxis,Lick.ILI2(startinterval:endinterval,1),Lick.ILI2(startinterval:endinterval,2),'*','Color',maltodextrin,'linewidth',1.5);
  350. xlabel('Lick Interval #');
  351. ylabel('Duration (s)');
  352. title(['Interlick intervals'])
  353. axis([1 30 0.13 0.19]);
  354. legend('Sucrose trials','Maltodextrin trials','location','northwest');
  355. subplot(4,4,15);
  356. hold on;
  357. errorbar(2,nanmean(Lick.ILI1(startinterval:endinterval,1)),nanste(Lick.ILI1(startinterval:endinterval,1),1),'*','Color',sucrose,'linewidth',1.5);
  358. errorbar(2,nanmean(Lick.ILI2(startinterval:endinterval,1)),nanste(Lick.ILI2(startinterval:endinterval,1),1),'*','Color',maltodextrin,'linewidth',1.5);
  359. if R_2R.LicksEarlyStats{2,7}<0.05
  360. plot(2,nanmean(Lick.ILI2(startinterval:endinterval,1))+0.005,'*','Color','k','MarkerSize',5);
  361. end
  362. set(gca,'xtick',[]);
  363. axis([1.5 2.5 0.14 0.17]);
  364. %% plotting sucrose preferences
  365. %Plot sucrose preference
  366. %colors
  367. NAc=[0.5 0.1 0.8];
  368. VP=[0.3 0.7 0.1];
  369. %data
  370. x=[1 2];
  371. NAcPref{1}=[81.7 81.3];
  372. NAcPref{2}=[77 73.9];
  373. NAcPref{3}=[37.4 74.6];
  374. NAcPref{4}=[71 95.6];
  375. NAcPref{5}=[89 83.6];
  376. NAcPref{6}=[94 93];
  377. VPPref{1}=[59.6 78.8];
  378. VPPref{2}=[88.8 85.8];
  379. VPPref{3}=[71.2 89];
  380. VPPref{4}=[87 76.6];
  381. VPPref{5}=[85.2 84.1];
  382. subplot(2,4,3);
  383. hold on;
  384. %do the first 2 first in order to get the legend right
  385. plot(x,NAcPref{1},'Marker','o','MarkerFaceColor',NAc,'LineWidth',1,'Color',NAc);
  386. plot(x,VPPref{1},'Marker','o','MarkerFaceColor',VP,'LineWidth',1,'Color',VP);
  387. for i=2:length(NAcPref)
  388. plot(x,NAcPref{i},'Marker','o','MarkerFaceColor',NAc,'LineWidth',1,'Color',NAc);
  389. end
  390. for i=2:length(VPPref)
  391. plot(x,VPPref{i},'Marker','o','MarkerFaceColor',VP,'LineWidth',1,'Color',VP);
  392. end
  393. axis([0.7 2.2 0 100]);
  394. title('Two-bottle choice');
  395. xlabel('Initial Final');
  396. ylabel('% sucrose consumption');
  397. legend('NAc rat','VP rat','location','southeast');
  398. plot([0 3],[50 50],':','color','k','linewidth',0.75);
  399. set(gca,'xtick',[])
  400. %% licks dependent on previous trial
  401. figure;
  402. Xaxis=[-2 12];
  403. Ishow=find(Tm>=Xaxis(1) & Tm<=Xaxis(2));
  404. time1=Tm(Ishow);
  405. c=[-1000 7500];ClimE=sign(c).*abs(c).^(1/4);%ColorMapExc
  406. colormap(jet);
  407. %colors
  408. sucrose=[.95 0.55 0.15];
  409. maltodextrin=[.9 0.3 .9];
  410. water=[0.00 0.75 0.75];
  411. total=[0.3 0.1 0.8];
  412. inh=[0.1 0.021154 0.6];
  413. exc=[0.9 0.75 0.205816];
  414. NAc=[0.5 0.1 0.8];
  415. VP=[0.3 0.7 0.1];
  416. %extra colors to make a gradient
  417. sucrosem=[.98 0.8 0.35];
  418. sucrosel=[1 1 0.4];
  419. maltodextrinm=[1 0.75 1];
  420. maltodextrinl=[1 0.8 1];
  421. Ev2=strcmp('RD1P1', Lick.Erefnames);
  422. Ev1=strcmp('RD1P2', Lick.Erefnames);
  423. Ev4=strcmp('RD2P1', Lick.Erefnames);
  424. Ev3=strcmp('RD2P2', Lick.Erefnames);
  425. psth1=nanmean(Lick.Ev(Ev1).PSTHraw(:,Ishow),1);
  426. sem1=nanste(Lick.Ev(Ev1).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  427. up1=psth1+sem1;
  428. down1=psth1-sem1;
  429. psthE=nanmean(Lick.Ev(Ev2).PSTHraw(:,Ishow),1);
  430. semE=nanste(Lick.Ev(Ev2).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  431. upE=psthE+semE;
  432. downE=psthE-semE;
  433. psth3=nanmean(Lick.Ev(Ev3).PSTHraw(:,Ishow),1);
  434. sem3=nanste(Lick.Ev(Ev3).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  435. up3=psth3+sem3;
  436. down3=psth3-sem3;
  437. psth4=nanmean(Lick.Ev(Ev4).PSTHraw(:,Ishow),1);
  438. sem4=nanste(Lick.Ev(Ev4).PSTHraw(:,Ishow),1); %calculate standard error of the mean
  439. up4=psth4+sem4;
  440. down4=psth4-sem4;
  441. %plotting
  442. subplot(1,1,1);
  443. hold on;
  444. plot(time1,psth1,'Color',sucrosem,'linewidth',1);
  445. plot(time1,psthE,'Color',sucrose,'linewidth',1);
  446. plot(time1,psth3,'Color',maltodextrinm,'linewidth',1);
  447. plot(time1,psth4,'Color',maltodextrin,'linewidth',1);
  448. patch([time1,time1(end:-1:1)],[up1,down1(end:-1:1)],sucrosem,'EdgeColor','none');alpha(0.5);
  449. patch([time1,time1(end:-1:1)],[upE,downE(end:-1:1)],sucrose,'EdgeColor','none');alpha(0.5);
  450. patch([time1,time1(end:-1:1)],[up3,down3(end:-1:1)],maltodextrinm,'EdgeColor','none');alpha(0.5);
  451. patch([time1,time1(end:-1:1)],[up4,down4(end:-1:1)],maltodextrin,'EdgeColor','none');alpha(0.5);
  452. title('Mean lick rate');
  453. %plot([-2 10],[0 0],':','color','k');
  454. plot([0 0],[-2 8],':','color','k','linewidth',0.75);
  455. axis([-2 12 0 7.5]);
  456. xlabel('Seconds post first rewarded lick');
  457. ylabel('Licks/s');
  458. legend('Sucrose after mal','Sucrose after suc','Maltodextrin after mal','Maltodextrin after suc');
  459. save('R_2R.mat','R_2R');