G_generateFigure5.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. %% generate figure 5 and S6
  2. % fourrier analysis - hierarchical clustering - Random forest approach on
  3. % early training dataset
  4. % statistics for the early training dataset
  5. clc;clear;close all;
  6. load ('Rearlytraining_light.mat');
  7. load ('Celltype_earlyTraining.mat');
  8. load('TRN_DT5_earlytrain.mat')
  9. Xevent=[-0.25 0.25];
  10. Yaxis=[-5 10];Xaxis=[1 357];
  11. Ishow=find(Tm>=Xevent(1) & Tm<=Xevent(2));
  12. time=[1:1:357];
  13. % ----------- COLORS ---------
  14. myblue=[0 113/255 188/255];
  15. mypurple=[200/255 0 255/255];
  16. mydarkblue=[0 0/255 255/255];
  17. TickSize=[0.015 0.02];
  18. Clim=[-5 5];
  19. DSconcat_ACQ_allsession=[];Coord_allsession=[];Ninfo_allsession=[];DSmeanz_ACQ_allsession=[];
  20. TRN_allsession=[];EXCINH_allsession=[];sessionID_allsession=[];
  21. for i=1:length(Ses)
  22. %normalization based on max
  23. for k=1:length(Erefnames)
  24. Ev(k).PSTH_norm1=normalize(Ses(i).Ev(k).PSTHraw,Ses(i).Ev(k).PSTHrawBL,1);
  25. end
  26. DSconcat_ACQ=[];DSmeanz_ACQ=[];
  27. %concat with normalized data
  28. DSconcat_ACQ = Ev(7).PSTH_norm1(:,Ishow);
  29. DSmeanz_ACQ = Ses(i).Ev(7).Meanz(:,1);
  30. for k=1:5
  31. DSconcat_ACQ = cat(2,DSconcat_ACQ,Ev(k).PSTH_norm1(:,Ishow));
  32. DSmeanz_ACQ = cat(2,DSmeanz_ACQ,Ses(i).Ev(k).MeanzPRE(:,1));
  33. DSmeanz_ACQ = cat(2,DSmeanz_ACQ,Ses(i).Ev(k).Meanz(:,1));
  34. end
  35. DSconcat_ACQ = cat(2,DSconcat_ACQ,Ev(6).PSTH_norm1(:,Ishow));
  36. DSmeanz_ACQ = cat(2,DSmeanz_ACQ,Ses(i).Ev(6).MeanzPRE(:,1));
  37. DSconcat_ACQ_allsession=cat(1,DSconcat_ACQ_allsession,DSconcat_ACQ);
  38. Coord_allsession=cat(1,Coord_allsession,Ses(i).Coord(:,4));
  39. Ninfo_allsession=cat(1,Ninfo_allsession,Ses(i).Ninfo);
  40. DSmeanz_ACQ_allsession=cat(1,DSmeanz_ACQ_allsession,DSmeanz_ACQ);
  41. TRN_allsession=cat(1,TRN_allsession,sesTRN(i).TRN(:,1));
  42. sessionID_allsession=cat(1,sessionID_allsession,repmat(i,length(Ses(i).TRN(:,1)),1));
  43. if i>3
  44. EXCINH_allsession=cat(1,EXCINH_allsession,sesTRN(i).TRN(:,2));
  45. end
  46. end
  47. s2={'YVG04','YVG05','YVG08','YVJ11','YVJ15'};
  48. for j=1:5
  49. for i=1:length(Ninfo_allsession)
  50. RatID(i,j)=strncmp(Ninfo_allsession{i,1},s2(j),5);
  51. end
  52. end
  53. RatID_ACQ=sum(RatID,2);
  54. % concat with Zscore
  55. DSconcatZ_ACQ_allsession=[];DSevent_ACQ_allsession=[];
  56. for i=1:length(Ses)
  57. DSconcat_ACQ=[];DSevent_ACQ=[];
  58. DSconcat_ACQ=Ses(i).Ev(7).PSTHz(:,Ishow);
  59. DSevent_ACQ=Ses(i).Ev(7).Meanz(:,1);
  60. for k=1:6 %loop through event
  61. DSconcat_ACQ=cat(2,DSconcat_ACQ,Ses(i).Ev(k).PSTHz(:,Ishow));
  62. DSevent_ACQ = cat(2,DSevent_ACQ,Ses(i).Ev(k).Meanz(:,1));
  63. end
  64. DSconcatZ_ACQ_allsession=cat(1,DSconcatZ_ACQ_allsession,DSconcat_ACQ);
  65. DSevent_ACQ_allsession=cat(1,DSevent_ACQ_allsession,DSevent_ACQ);
  66. end
  67. selection=Coord_allsession~=0 & Celltype(:,2)==1 & ~isnan(mean(DSconcat_ACQ_allsession,2));
  68. DSconcat_ACQshort=DSconcat_ACQ_allsession(selection,:);
  69. DSevent_ACQshort=DSevent_ACQ_allsession(selection,:);
  70. Coord_short=Coord_allsession(selection,:);
  71. Ninfo_short=Ninfo_allsession(selection,:);
  72. %% Clustering on phasic and non phasic neurons with Fourier analysis
  73. close all;
  74. f_low=1;f_high=4;
  75. [X_all,f_all,P_all,Nt_all]=myfft(DSconcat_ACQshort',0.01,1);
  76. total_power=sum(P_all);
  77. P_all_norm = bsxfun(@rdivide,P_all, total_power);
  78. %figure;plot(f_all,P_all_norm);set(gca,'ylim',[0 0.6]);xlabel('Hz');ylabel('Normalized power');
  79. %title('Normalized FFT of all neurons');
  80. a=find(f_all>f_low);b=find(f_all<f_high);
  81. interval_to_sum=[a(1) b(end)];
  82. lower_window_sum_all=sum(P_all_norm(1:a(1),:));
  83. upper_window_sum_all=sum(P_all_norm(a(1):b(end),:));
  84. ratio_all=lower_window_sum_all./upper_window_sum_all;
  85. X_ratio=[[lower_window_sum_all]' [upper_window_sum_all]']; %#ok<NBRAK>
  86. eva_Ch_ratio = evalclusters(X_ratio,'linkage','CalinskiHarabasz','KList',[1:10]);
  87. phasicID=eva_Ch_ratio.OptimalY;
  88. Z = linkage(X_ratio,'ward'); % X is the data set, neuron in rows, features in columns
  89. c = cluster(Z,'Maxclust',3); % determine the number cluster here)
  90. D = pdist(X_ratio);
  91. leafOrder = optimalleaforder(Z,D);
  92. cutoff = median([Z(end-2,3) Z(end-1,3)]);
  93. figure
  94. subplot(9,4,[29 33])
  95. dendrogram(Z,'ColorThreshold',cutoff, 'Reorder',leafOrder);
  96. %% Figure Fourier transform
  97. c_ratio=eva_Ch_ratio.OptimalY;
  98. for i=1:length(c_ratio)
  99. if c_ratio(i,1)==1
  100. color(i,:)=[255/255 0/255 0/255]; %phasic red
  101. elseif c_ratio(i,1)==2
  102. color(i,:)=[0 255/255 0/255]; %sustained green
  103. end
  104. end
  105. subplot(10,4,[1 2 5 6])
  106. scatter(lower_window_sum_all,upper_window_sum_all,[],color)
  107. hold on
  108. title(strcat('hierarchical clustering'))
  109. xlabel('lower_window_sum_all') % x-axis label
  110. ylabel('upper_window_sum_all,ordinates')% y-axis label
  111. hold off
  112. Xlimit=find(f_all<30);
  113. subplot(10,4,[3 4 7 8 11 12 15 16])
  114. P_all_norm=P_all_norm';
  115. selectionPhasic=c_ratio(:,1)==1;
  116. selectionNonPhasic=c_ratio(:,1)==2;
  117. Phasicmean=nanmean(P_all_norm(selectionPhasic,Xlimit'),1);
  118. Phasicsem=nanste(P_all_norm(selectionPhasic,Xlimit'),1);
  119. Phasicup=Phasicmean+Phasicsem;
  120. Phasicdown=Phasicmean-Phasicsem;
  121. nonphasicmean=nanmean(P_all_norm(selectionNonPhasic,Xlimit'),1);
  122. nonphasicsem=nanste(P_all_norm(selectionNonPhasic,Xlimit'),1);
  123. nonphasicup=nonphasicmean+nonphasicsem;
  124. nonphasicdown=nonphasicmean-nonphasicsem;
  125. timeX=1:1:length(Xlimit);
  126. hold on
  127. patch([timeX,timeX(end:-1:1)],[Phasicup,Phasicdown(end:-1:1)],myblue,'EdgeColor','none');alpha(0.5);
  128. g1=plot(timeX,Phasicmean,'Color',myblue,'linewidth',1.5);
  129. patch([timeX,timeX(end:-1:1)],[nonphasicup,nonphasicdown(end:-1:1)],'r','EdgeColor','none');alpha(0.5);
  130. g2=plot(timeX,nonphasicmean,'r','linewidth',1.5);
  131. plot([0 30], [0 0],'LineStyle',':','Color','k');
  132. set(gca,'XTick',[1:21.8:327]);
  133. hold off
  134. %% visualization classes
  135. for i=1:2
  136. ind=find(phasicID==i);
  137. t=num2str(i);
  138. Clim=[-5 5];
  139. DSconcat_ACQ_class=[];SORTimg=[];MaxValDLS=[];MeanValDLS=[]; MaxTimeDLS=[];TMP=[];NNid=[];
  140. DSconcat_ACQ_class=DSconcat_ACQshort(ind,:);
  141. for NN=1:size(DSconcat_ACQ_class,1)
  142. MeanValDLS(NN,1)=mean(DSconcat_ACQ_class(NN,52:306),2);
  143. [MaxValDLS(NN,1),MaxInd]=max(DSconcat_ACQ_class(NN,:));
  144. MaxTimeDLS(NN,1)=time(time(1)+MaxInd-1);
  145. if i==2
  146. MaxTimePhasic=MaxTimeDLS;
  147. end
  148. end
  149. if i==1
  150. TMP=MeanValDLS;
  151. subplot(10,4,[17 18 21 22 25 26 29 30 33 34 37 38])
  152. elseif i==2
  153. TMP=MeanValDLS;
  154. subplot(10,4,[19 20 23 24 27 28 31 32 35 36 39 40])
  155. end
  156. TMP(isnan(TMP))=0; %To place the neurons with no onset/duration/peak at the top of the color-coded map
  157. [~,SORTimg]=sort(TMP);
  158. %NNid=cell2mat(Ninfo(phasic_neuron_selection,3));NNid2=NNid(SORTimg);
  159. DSconcat_ACQ_class=DSconcat_ACQ_class(SORTimg,:);
  160. imagesc(time,[1 size(DSconcat_ACQ_class,1)],DSconcat_ACQ_class);%colorbar;axis tight;
  161. colormap(jet);
  162. hold on
  163. plot([51 51],[size(DSconcat_ACQ_class,1)+0.5 0.5],'k')
  164. plot([102 102],[size(DSconcat_ACQ_class,1)+0.5 0.5],'k')
  165. plot([153 153],[size(DSconcat_ACQ_class,1)+0.5 0.5],'k')
  166. plot([204 204],[size(DSconcat_ACQ_class,1)+0.5 0.5],'k')
  167. plot([255 255],[size(DSconcat_ACQ_class,1)+0.5 0.5],'k')
  168. plot([306 306],[size(DSconcat_ACQ_class,1)+0.5 0.5],'k')
  169. set(gca,'XTick',[0:25.5:357]);
  170. hold off
  171. end
  172. ClassACQ(1:length(Celltype),1)=0;
  173. ClassACQ(selection,1)=phasicID;
  174. %% Run random forest for phasic neurons
  175. load('ClassHC.mat' );
  176. XTrainingDATA=ClassPHAS(:,2:4);
  177. YTrainingDATA=ClassPHAS(:,1);
  178. LIwin=[26:51];%post lever insertion window
  179. LPwin=[52:280];%pre-1stLP to pre-lastLP window
  180. PEwin=[307:332];% pre-PE window
  181. binLI=mean(DSconcat_ACQ_allsession(:,LIwin),2);
  182. binLP=mean(DSconcat_ACQ_allsession(:,LPwin),2);
  183. binPE=mean(DSconcat_ACQ_allsession(:,PEwin),2);
  184. binnedDS=cat(2,binLI,binLP,binPE);
  185. XTestingDATA=binnedDS(ClassACQ(:,1)==2,:);
  186. model = classRF_train(XTrainingDATA, YTrainingDATA); % train Random Forest model
  187. % prepare the data for FOR loop
  188. X = {XTrainingDATA, XTestingDATA};
  189. Y = {YTrainingDATA};
  190. classifier = {'Raw Data','Random Forest'};
  191. mc = ['r','g']; msym = ['o','o']; msiz = [3,15];
  192. for i = 1 : 2 % iterate through training and test data
  193. x = X{i}; y = Y;
  194. for j = 1 : 2 % iterate through different classifiers
  195. switch(j) % y_hat = running models ? model predictions : y
  196. case 1 % raw data
  197. y_hat = y;
  198. case 2 % Random Forest
  199. y_hat = classRF_predict(x ,model); % Random Forest predictions
  200. if i==2
  201. Class_Acq(:,1)=y_hat;
  202. end
  203. end
  204. end
  205. end
  206. ClassACQ(1:length(Celltype),2)=0;
  207. ClassACQ(ClassACQ(:,1)==2,2)=Class_Acq;
  208. %% Random forest for non phasic neurons
  209. XTrainingDATA_NP=ClassNONPHASIC(:,2:4);
  210. YTrainingDATA_NP=ClassNONPHASIC(:,1);
  211. XTestingDATA_NP=binnedDS(ClassACQ(:,1)==1,:);
  212. model = classRF_train(XTrainingDATA_NP, YTrainingDATA_NP); % train Random Forest model
  213. % prepare the data for FOR loop
  214. X = {XTrainingDATA_NP, XTestingDATA_NP};
  215. Y = {YTrainingDATA_NP};
  216. classifier = {'Raw Data','Random Forest'};
  217. mc = ['r','g']; msym = ['o','o']; msiz = [3,15];
  218. for i = 1 : 2 % iterate through training and test data
  219. x = X{i}; y = Y;
  220. for j = 1 : 2 % iterate through different classifiers
  221. switch(j) % y_hat = running models ? model predictions : y
  222. case 1 % raw data
  223. y_hat = y;
  224. case 2 % Random Forest
  225. y_hat = classRF_predict(x ,model); % Random Forest predictions
  226. if i==2
  227. Class_Acq_NP(:,1)=y_hat;
  228. end
  229. end
  230. end
  231. end
  232. ClassACQ(ClassACQ(:,1)==1,2)=Class_Acq_NP+3;
  233. %% selection of neurons per session per class
  234. % 1-3 is for phasic and 4-5 for non phasic
  235. for i=1:max(Celltype(:,1))
  236. InDSsel=Ses(i).Coord(:,4)~=0;
  237. Ses(i).Class(InDSsel,1)=ClassACQ(Celltype(:,1)==i,2);
  238. Ses(i).Celltype(InDSsel,1)=Celltype(Celltype(:,1)==i,2);
  239. end
  240. for k=1:max(ClassACQ(:,2))
  241. DLSconcat_ACQ_3ds(k).DLS=[];
  242. DMSconcat_ACQ_3ds(k).DMS=[];
  243. for i=4:13
  244. DLSselection=Ses(i).Coord(:,4)==10 & Ses(i).Class(:,1)==k & Ses(i).Celltype(:,1)==1;
  245. DMSselection=Ses(i).Coord(:,4)==20 & Ses(i).Class(:,1)==k & Ses(i).Celltype(:,1)==1;
  246. DLSconcat_ACQ=[];DMSconcat_ACQ=[];
  247. DLSconcat_ACQ = cat(2,DLSconcat_ACQ,Ses(i).Ev(7).PSTHz(DLSselection,Ishow));
  248. DMSconcat_ACQ = cat(2,DMSconcat_ACQ,Ses(i).Ev(7).PSTHz(DMSselection,Ishow));
  249. for j=1:6
  250. DLSconcat_ACQ = cat(2,DLSconcat_ACQ,Ses(i).Ev(j).PSTHz(DLSselection,Ishow));
  251. DMSconcat_ACQ = cat(2,DMSconcat_ACQ,Ses(i).Ev(j).PSTHz(DMSselection,Ishow));
  252. end
  253. MeanDLS(k).img(i-3,:)=nanmean(DLSconcat_ACQ,1);
  254. MeanDMS(k).img(i-3,:)=nanmean(DMSconcat_ACQ,1);
  255. if i>10
  256. DLSconcat_ACQ_3ds(k).DLS=cat(1,DLSconcat_ACQ_3ds(k).DLS,DLSconcat_ACQ);
  257. DMSconcat_ACQ_3ds(k).DMS=cat(1,DMSconcat_ACQ_3ds(k).DMS,DMSconcat_ACQ);
  258. DLSsem(k,:)=nanste(DLSconcat_ACQ(:,time),1);
  259. DMSsem(k,:)=nanste(DMSconcat_ACQ(:,time),1);
  260. end
  261. end
  262. end
  263. %% heat maps classes of neurons
  264. Eventnames={'';'LI';'';'LP1';'';'LP2';'';'LP3';'';'LP4';'';'LP5';'';'PE'};
  265. titlegraphDLS={'DLS - Start','DLS - Stop', 'DLS - middle','DLS - INH','DLS - EXC'};
  266. titlegraphDMS={'DMS - Start','DMS - Stop', 'DMS - middle','DMS - INH','DMS - EXC'};
  267. %titlePSTH={'Inhibited neurons', 'Excited neurons'};
  268. BrainRegion=[10 20];
  269. figure
  270. nplot=0;
  271. for k=1:max(ClassACQ(:,2)) % loop thru non phasic classes
  272. if k<4 || k==5
  273. nplot=nplot+1;
  274. elseif k==4
  275. nplot=nplot+10;
  276. end
  277. subplot(6,4,2+(nplot-1))
  278. imagesc(time,[1 size(MeanDLS(k).img,1)],MeanDLS(k).img,Clim); %colorbar;axis tight;
  279. colormap(jet);
  280. %colormap(plasma);
  281. set(gca,'XTick',[0:25.5:357]);
  282. set(gca,'xticklabel',Eventnames)
  283. title(titlegraphDLS(k));
  284. ylabel('sessions');
  285. hold on
  286. plot([51 51],[size(MeanDLS(k).img,1)+0.5 0.5],'k')
  287. plot([102 102],[size(MeanDLS(k).img,1)+0.5 0.5],'k')
  288. plot([153 153],[size(MeanDLS(k).img,1)+0.5 0.5],'k')
  289. plot([204 204],[size(MeanDLS(k).img,1)+0.5 0.5],'k')
  290. plot([255 255],[size(MeanDLS(k).img,1)+0.5 0.5],'k')
  291. plot([306 306],[size(MeanDLS(k).img,1)+0.5 0.5],'k')
  292. hold off
  293. subplot(6,4,6+(nplot-1))
  294. imagesc(time,[1 size(MeanDMS(k).img,1)],MeanDMS(k).img,Clim); %colorbar;axis tight;
  295. colormap(jet);
  296. set(gca,'XTick',[0:25.5:357]);
  297. set(gca,'xticklabel',Eventnames)
  298. title(titlegraphDMS(k));
  299. ylabel('sessions');
  300. hold on
  301. plot([51 51],[size(MeanDMS(k).img,1)+0.5 0.5],'k')
  302. plot([102 102],[size(MeanDMS(k).img,1)+0.5 0.5],'k')
  303. plot([153 153],[size(MeanDMS(k).img,1)+0.5 0.5],'k')
  304. plot([204 204],[size(MeanDMS(k).img,1)+0.5 0.5],'k')
  305. plot([255 255],[size(MeanDMS(k).img,1)+0.5 0.5],'k')
  306. plot([306 306],[size(MeanDMS(k).img,1)+0.5 0.5],'k')
  307. hold off
  308. subplot(6,4,10+(nplot-1))
  309. DLSpsth=nanmean(DLSconcat_ACQ_3ds(k).DLS,1);
  310. DLS_sem=nanste(DLSconcat_ACQ_3ds(k).DLS,1);
  311. DLSup=DLSpsth+DLS_sem;
  312. DLSdown=DLSpsth-DLS_sem;
  313. DMSpsth=nanmean(DMSconcat_ACQ_3ds(k).DMS,1);
  314. DMS_sem=nanste(DMSconcat_ACQ_3ds(k).DMS,1);
  315. DMSup=DMSpsth+DMS_sem;
  316. DMSdown=DMSpsth-DMS_sem;
  317. hold on;
  318. patch([time,time(end:-1:1)],[DLSup,DLSdown(end:-1:1)],myblue,'EdgeColor','none');alpha(0.5);
  319. plot(time,DLSpsth,'Color',myblue,'linewidth',1.5);
  320. patch([time,time(end:-1:1)],[DMSup,DMSdown(end:-1:1)],'r','EdgeColor','none');alpha(0.5);
  321. plot(time,DMSpsth,'r','linewidth',1.5);
  322. yaxis=[round(min(DMSdown)-0.5,0) round(max(DMSup)+0.5,0)];
  323. plot([0 357], [0 0],'LineStyle',':','Color','k');
  324. plot([51 51],yaxis,'LineStyle',':','Color','k')
  325. plot([102 102],yaxis,'LineStyle',':','Color','k')
  326. plot([153 153],yaxis,'LineStyle',':','Color','k')
  327. plot([204 204],yaxis,'LineStyle',':','Color','k')
  328. plot([255 255],yaxis,'LineStyle',':','Color','k')
  329. plot([306 306],yaxis,'LineStyle',':','Color','k')
  330. axis([Xaxis,yaxis]);
  331. set(gca,'XTick',0:25.5:357);
  332. set(gca,'xticklabel',Eventnames)
  333. ylabel('z-score');
  334. hold off
  335. end
  336. for j=1:2
  337. for i=4:13
  338. DLSselectionP=Ses(i).Coord(:,4)==BrainRegion(1) & (Ses(i).Class(:,1)<4) & Ses(i).Celltype(:,1)==1 ;
  339. DMSselectionP=Ses(i).Coord(:,4)==BrainRegion(2) & (Ses(i).Class(:,1)<4) & Ses(i).Celltype(:,1)==1 ;
  340. if j==1;DSselection=logical(DLSselectionP); else DSselection=logical(DMSselectionP);end
  341. DS_Nb_tot_phasic(i-3,j)=sum(DSselection);
  342. PercentPhasic(i-3,1+(j-1)*2)=100*sum(DSselection)/sum(Ses(i).Coord(:,4)==BrainRegion(j) & Ses(i).Celltype(:,1)==1);
  343. PercentPhasic(i-3,2+(j-1)*2)=100-PercentPhasic(i-3,1+(j-1)*2);
  344. end
  345. end
  346. % subplot(6,4,1) % plot DLS phasic vs non phasic
  347. % bp1=barh(PercentPhasic(:,1:2),1,'stacked');
  348. % axis([0 100 0.5 10.5])
  349. % subplot(6,4,2) % plot DMS phasic vs non phasic
  350. % bp2=barh(PercentPhasic(:,3:4),1,'stacked');
  351. % axis([0 100 0.5 10.5])
  352. %
  353. %% Proportion of neurons
  354. for k=1:3
  355. for i=4:13
  356. DLSselection=Ses(i).Coord(:,4)==BrainRegion(1) & (Ses(i).Class(:,1)==k) & Ses(i).Celltype(:,1)==1;
  357. DMSselection=Ses(i).Coord(:,4)==BrainRegion(2) & (Ses(i).Class(:,1)==k) & Ses(i).Celltype(:,1)==1;
  358. DLS_prop_Phasic(i-3,k)=100*sum(DLSselection)/(sum(Ses(i).Coord(:,4)==BrainRegion(1) & Ses(i).Celltype(:,1)==1 & Ses(i).Class(:,1)<4 & Ses(i).Class(:,1)~=0));
  359. DMS_prop_Phasic(i-3,k)=100*sum(DMSselection)/(sum(Ses(i).Coord(:,4)==BrainRegion(2) & Ses(i).Celltype(:,1)==1 & Ses(i).Class(:,1)<4 & Ses(i).Class(:,1)~=0));
  360. DLSselectionNumber(i-3,k)=sum(DLSselection);
  361. DMSselectionNumber(i-3,k)=sum(DMSselection);
  362. end
  363. end
  364. subplot(6,4,1)
  365. b1=barh(DLS_prop_Phasic,1,'stacked');
  366. axis([0 100 0.5 10.5])
  367. subplot(6,4,5)
  368. b2=barh(DMS_prop_Phasic,1,'stacked');
  369. axis([0 100 0.5 10.5])
  370. for k=1:2
  371. for i=4:13
  372. DLSselection=Ses(i).Coord(:,4)==BrainRegion(1) & (Ses(i).Class(:,1)==k+3) & Ses(i).Celltype(:,1)==1;
  373. DMSselection=Ses(i).Coord(:,4)==BrainRegion(2) & (Ses(i).Class(:,1)==k+3) & Ses(i).Celltype(:,1)==1;
  374. DLS_prop_nonPhasic(i-3,k)=100*sum(DLSselection)/(sum(Ses(i).Coord(:,4)==BrainRegion(1) & Ses(i).Celltype(:,1)==1 & Ses(i).Class(:,1)>3 & Ses(i).Class(:,1)~=0));
  375. DMS_prop_nonPhasic(i-3,k)=100*sum(DMSselection)/(sum(Ses(i).Coord(:,4)==BrainRegion(2) & Ses(i).Celltype(:,1)==1 & Ses(i).Class(:,1)>3 & Ses(i).Class(:,1)~=0));
  376. DLSselectionNumber(i-3,k)=sum(DLSselection);
  377. DMSselectionNumber(i-3,k)=sum(DMSselection);
  378. end
  379. end
  380. subplot(6,4,13)
  381. b1=barh(DLS_prop_nonPhasic,1,'stacked');
  382. axis([0 100 0.5 10.5])
  383. subplot(6,4,17)
  384. b2=barh(DMS_prop_nonPhasic,1,'stacked');
  385. axis([0 100 0.5 10.5])
  386. %% %% make table for statistics
  387. selectDT5Session=sessionID_allsession(:,1)>3;
  388. table_ACQ=cat(2,sessionID_allsession(selectDT5Session,1),Coord_allsession(selectDT5Session,1),Celltype(selectDT5Session,2),ClassACQ(selectDT5Session,1),ClassACQ(selectDT5Session,2),DSmeanz_ACQ_allsession(selectDT5Session,:),TRN_allsession(selectDT5Session,1),EXCINH_allsession(:,1), RatID_ACQ(selectDT5Session,1));
  389. save('table_ACQ.mat','table_ACQ')
  390. nbevent=[1:12];
  391. selectionSTAT=table_ACQ(:,2)~=0 & table_ACQ(:,3)==1 & table_ACQ(:,18)~=0;
  392. sessionCat=categorical(table_ACQ(selectionSTAT,1));
  393. tableSTAT=array2table(table_ACQ(selectionSTAT,1:20),'VariableNames',{'session','region','celltype','phasicID','class','win1','win2','win3','win4','win5','win6','win7','win8','win9','win10','win11','win12','TRN','EXCINH','habit'});
  394. tableSTAT.session=categorical(tableSTAT.session);
  395. tableSTAT.region=categorical(tableSTAT.region);
  396. tableSTAT.habit=categorical(tableSTAT.habit);
  397. rm = fitrm(tableSTAT,'win1-win12~region*session','WithinDesign',nbevent');
  398. ranovatbl_event = ranova(rm);
  399. Btw_ranovatbl_event = anova(rm);
  400. SphericityAssumption=mauchly(rm);
  401. posthoc = multcompare(rm,'session', 'by', 'region');
  402. rmh = fitrm(tableSTAT,'win1-win12~region*session*habit','WithinDesign',nbevent');
  403. ranovatbl_event_habit = ranova(rmh);
  404. Btw_ranovatbl_event_habit = anova(rmh);
  405. SphericityAssumption_habit=mauchly(rmh);
  406. posthoc_habit = multcompare(rmh,'region', 'by', 'habit');
  407. % for i=1:max(table_ACQ(:,5))
  408. for i=1:3 %loop thru phasic neurons, problem, not enough neurons in non phasic classes
  409. selectionSTAT1=table_ACQ(:,2)~=0 & table_ACQ(:,3)==1 & table_ACQ(:,5)==i;
  410. tableSTAT1=array2table(table_ACQ(selectionSTAT1,1:20),'VariableNames',{'session','region','celltype','phasicID','class','win1','win2','win3','win4','win5','win6','win7','win8','win9','win10','win11','win12','TRN','EXCINH','habit'});
  411. tableSTAT1.session=categorical(tableSTAT1.session);
  412. tableSTAT1.region=categorical(tableSTAT1.region);
  413. tableSTAT1.habit=categorical(tableSTAT1.habit);
  414. rm = fitrm(tableSTAT1,'win1-win12~region*session','WithinDesign',nbevent');
  415. stat(i).ranovatbl_event = ranova(rm);
  416. stat(i).Btw_ranovatbl_event = anova(rm);
  417. [~,stat(i).LIevent,~]=anovan(table_ACQ(selectionSTAT1,6),{table_ACQ(selectionSTAT1,2)},'varnames',{'region'}, 'display','off');
  418. [~,stat(i).LRevent,~]=anovan(table_ACQ(selectionSTAT1,16),{table_ACQ(selectionSTAT1,2)},'varnames',{'region'}, 'display','off');
  419. [~,stat(i).PEevent,~]=anovan(table_ACQ(selectionSTAT1,17),{table_ACQ(selectionSTAT1,2)},'varnames',{'region'}, 'display','off');
  420. rmh = fitrm(tableSTAT1,'win1-win12~region*session*habit','WithinDesign',nbevent');
  421. stat(i).ranovatbl_event_habit = ranova(rmh);
  422. stat(i).Btw_ranovatbl_habit = anova(rmh);
  423. stat(i).posthoc_habit = multcompare(rmh,'region', 'by', 'habit');
  424. end
  425. for i=1:10
  426. selectionSTAT2=table_ACQ(:,2)~=0 & table_ACQ(:,3)==1 & table_ACQ(:,1)==i+3 & table_ACQ(:,4)==1;
  427. [chi(i).tbl1,chi(i).chi2,chi(i).p1,chi(i).labels] = crosstab(table_ACQ(selectionSTAT2,2),table_ACQ(selectionSTAT2,5));
  428. end
  429. save('RacqHabit2_light.mat','Erefnames','Ses','Tm')