H_generateFigure6.m 19 KB

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