figure_binmod.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. function figure_binmod(fld)
  2. fprintf('\n======================================================\n');
  3. fprintf('-- Creating Figure binmod --\n');
  4. fprintf('======================================================\n');
  5. loaddir = fullfile(fld.basedir,'results','figure_neurotrace');
  6. savedir = fullfile(fld.basedir,'results','figure_binmod');
  7. mkdir(savedir);
  8. %% settings
  9. green = [23, 105, 13]./255;
  10. red = [201, 0, 34]./255;
  11. cols = [green; 0.3 0.3 0.3; red; 1.00,0.84,0.00];
  12. snrthres = 2.5; mindays = 3;
  13. do_cleantraces = true; % if true we throw out artefact traces
  14. bin.sz = 10; % ms
  15. bin.minmax = [0 250];
  16. %% plots
  17. % load traces
  18. monkeys = {'M1','M2'};
  19. %% plot
  20. f1 = figure;
  21. set(f1,'Position',[500 500 1600 800]);
  22. bonfcorr = true;
  23. if do_cleantraces
  24. load(fullfile(loaddir,'Traces_SNR_trialbased.mat'),...
  25. 's_traces_ALL','recsites','rsinc');
  26. end
  27. % individual animals
  28. for mi = 1:2
  29. monkey = monkeys{mi};
  30. load(fullfile(loaddir, [monkey '_averages_snr' num2str(snrthres) ...
  31. '_mindays' num2str(mindays) '.mat']),...
  32. 'traces','tracesLUT','env_t');
  33. % bin these traces
  34. bb_l = bin.minmax(1):bin.sz:bin.minmax(2);
  35. bb_r = bb_l+bin.sz;
  36. bb_c = (bb_l+bb_r)/2;
  37. if do_cleantraces
  38. tmp_traces=[]; tmp_LUT=[];
  39. for cond=1:3
  40. tmp_traces = [tmp_traces ; ...
  41. s_traces_ALL{mi,cond}(rsinc{mi,cond},:)];
  42. tmp_LUT = [tmp_LUT ; ...
  43. recsites{mi,cond}(rsinc{mi,cond}) ...
  44. cond.*ones(sum(rsinc{mi,cond}),1)];
  45. end
  46. traces_ = traces; tracesLUT_ = tracesLUT;
  47. traces = tmp_traces; tracesLUT = tmp_LUT;
  48. end
  49. traces_bin = nan(size(traces,1),length(bb_c));
  50. for sidx = 1:size(traces,1)
  51. for bidx = 1:length(bb_l)
  52. bbool = (env_t.*1e3)>=bb_l(bidx) & (env_t.*1e3)<bb_r(bidx);
  53. traces_bin(sidx,bidx) = mean(traces(sidx,bbool));
  54. end
  55. end
  56. traces_ALL{mi} = traces_bin;
  57. tracesLUT_ALL{mi} = tracesLUT;
  58. env_t_ALL{mi} = bb_c;
  59. figure(f1)
  60. mns = []; sems = []; trcs = cell(0);
  61. subplot(2,3,mi+1); hold on;
  62. for cond = 1:3
  63. incl = tracesLUT(:,2)==cond;
  64. incl_ALL{mi,cond} = incl;
  65. % calculate the mean across channels
  66. get_traces = traces_bin(incl,:);
  67. s_traces = get_traces;
  68. s_traces_ALL{mi,cond} = s_traces;
  69. trcs{cond} = s_traces; % for calculating the modulation onset
  70. end
  71. df = trcs{1} - trcs{2}; % difference for each channel separately
  72. mn = mean(df);
  73. csem = std(trcs{1} - trcs{2})./sqrt(size(trcs{1},1));
  74. % stats (wrong but something)
  75. p=nan(1,size(df,2));
  76. for bidx = 1:size(df,2)
  77. [h,p(bidx)] = ttest(df(:,bidx));
  78. end
  79. if bonfcorr; bonf = size(df,2); else; bonf = 1; end
  80. bar(bb_c,mn,'FaceColor',cols(1,:),'BarWidth',1);
  81. bar(bb_c(p>0.05/bonf),mn(p>0.05/bonf),...
  82. 'FaceColor',[.5 .5 .5],'BarWidth',1);
  83. errorbar(bb_c,mn,csem,'LineStyle','none','Color','k');
  84. title([monkeys{mi} ' TARG']); xlabel('time(ms)'); ylabel('dMUA');
  85. set(gca,'ylim',[-0.04 0.14]);
  86. firstsig = find(p<0.05/bonf & mn>0,1,'first');
  87. fprintf(['M' num2str(mi) '-T: First sign. positive bin at ' ...
  88. num2str(bb_c(firstsig)) '\n'])
  89. subplot(2,3,mi+4); hold on;
  90. df = trcs{3} - trcs{2}; % difference for each channel separately
  91. mn = mean(df);
  92. csem = std(trcs{3} - trcs{2})./sqrt(size(trcs{3},1));
  93. % stats (wrong but something)
  94. p=nan(1,size(df,2));
  95. for bidx = 1:size(df,2)
  96. [h,p(bidx)] = ttest(df(:,bidx));
  97. end
  98. if bonfcorr; bonf = size(df,2); else; bonf = 1; end
  99. bar(bb_c,mn,'FaceColor',cols(3,:),'BarWidth',1);
  100. bar(bb_c(p>0.05/bonf),mn(p>0.05/bonf),...
  101. 'FaceColor',[.5 .5 .5],'BarWidth',1);
  102. errorbar(bb_c,mn,csem,'LineStyle','none','Color','k');
  103. title([monkeys{mi} ' SD']); xlabel('time(ms)'); ylabel('dMUA');
  104. set(gca,'ylim',[-0.12 0.05]);
  105. firstsig = find(p<0.05/bonf & mn>0,1,'first');
  106. fprintf(['M' num2str(mi) '-SD: First sign. positive bin at ' ...
  107. num2str(bb_c(firstsig)) '\n'])
  108. end
  109. % pooled animals
  110. for cond = 1:3
  111. incl = [incl_ALL{1,cond}; incl_ALL{2,cond}];
  112. % calculate the mean across channels
  113. traces = [traces_ALL{1}; traces_ALL{2}];
  114. get_traces = traces(incl,:);
  115. s_traces = get_traces;
  116. trcs{cond} = s_traces; % for calculating the modulation onset
  117. end
  118. inRF = {'target','','distractor'};
  119. subplot(2,3,1);hold on
  120. df = trcs{1} - trcs{2}; % difference for each channel separately
  121. mn = mean(df);
  122. csem = std(trcs{1} - trcs{2})./sqrt(size(trcs{1},1));
  123. % stats (wrong but something)
  124. p=nan(1,size(df,2));
  125. for bidx = 1:size(df,2)
  126. [h,p(bidx)] = ttest(df(:,bidx));
  127. end
  128. if bonfcorr; bonf = size(df,2); else; bonf = 1; end
  129. bar(bb_c,mn,'FaceColor',cols(1,:),'BarWidth',1);
  130. bar(bb_c(p>0.05/bonf),mn(p>0.05/bonf),...
  131. 'FaceColor',[.5 .5 .5],'BarWidth',1);
  132. errorbar(bb_c,mn,csem,'LineStyle','none','Color','k');
  133. title('BOTH monkeys TARG'); xlabel('time(ms)'); ylabel('dMUA');
  134. set(gca,'ylim',[-0.04 0.14]);
  135. firstsig = find(p<0.05/bonf & mn>0,1,'first');
  136. fprintf(['POOLED-T: First sign. positive bin at ' ...
  137. num2str(bb_c(firstsig)) '\n'])
  138. subplot(2,3,4);hold on
  139. df = trcs{3} - trcs{2}; % difference for each channel separately
  140. mn = mean(df);
  141. csem = std(trcs{3} - trcs{2})./sqrt(size(trcs{3},1));
  142. % stats (wrong but something)
  143. p=nan(1,size(df,2));
  144. for bidx = 1:size(df,2)
  145. [h,p(bidx)] = ttest(df(:,bidx));
  146. end
  147. if bonfcorr; bonf = size(df,2); else; bonf = 1; end
  148. bar(bb_c,mn,'FaceColor',cols(3,:),'BarWidth',1);
  149. bar(bb_c(p>0.05/bonf),mn(p>0.05/bonf),...
  150. 'FaceColor',[.5 .5 .5],'BarWidth',1);
  151. errorbar(bb_c,mn,csem,'LineStyle','none','Color','k');
  152. title('BOTH monkeys SD'); xlabel('time(ms)'); ylabel('dMUA');
  153. set(gca,'ylim',[-0.12 0.05]);
  154. text(gca,10,-0.1,'Colored bars: p<0.05, Bonf. corr.')
  155. firstsig = find(p<0.05/bonf & mn>0,1,'first');
  156. fprintf(['POOLED-SD: First sign. positive bin at ' ...
  157. num2str(bb_c(firstsig)) '\n'])
  158. %% save figure
  159. figure(f1)
  160. saveas(gcf,fullfile(savedir,'figure_binmod.svg'));