figure_neuropriming.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. function figure_neuropriming(fld)
  2. fprintf('\n======================================================\n');
  3. fprintf('-- Creating Figure neuropriming --\n');
  4. fprintf('======================================================\n');
  5. %% settings
  6. yellow = [247 148 29]./255;
  7. blue = [27 117 188]./255;
  8. cols = [blue; yellow];
  9. snrthres = 2.5;
  10. smoothfact = 15;
  11. mindays = 3;
  12. falpha = 0.4; % set to 1 for converting to illustrator
  13. %% plots
  14. % load traces
  15. monkeys = {'M1','M2'};
  16. wm = [];
  17. f1 = figure; set(gcf,'Position',[200 500 1200 600]);
  18. f2 = figure; set(gcf,'Position',[200 500 1200 600]);
  19. f1b = figure; set(gcf,'Position',[100 100 600 1200]);
  20. f2b = figure; set(gcf,'Position',[100 100 600 1200]);
  21. for mi = 1:2
  22. monkey = monkeys{mi};
  23. savedir = fullfile(fld.basedir, 'results','figure_neuropriming');
  24. load(fullfile(savedir, [monkey '_averages_snr' num2str(snrthres) '_mindays' num2str(mindays) '.mat']),...
  25. 'targmod','distmod','targmag','distmag','tracesLUT','env_t');
  26. % smooth first
  27. q = []; q2 = [];
  28. for i = 1:size(targmod)
  29. q(i,:) = smooth(targmod(i,:),smoothfact);
  30. q2(i,:) = smooth(distmod(i,:),smoothfact);
  31. end
  32. targmod = q;
  33. distmod = q2;
  34. %% plot the effect of shape change on target modulation
  35. figure(f1); subplot(2,3,mi+1);
  36. [D, q] = make_plot(env_t,targmod,tracesLUT.shapeswitch,'Shape');
  37. DShape{mi,1}=D;
  38. DShape_q{mi,1}=q;
  39. ylabel('target modulation');
  40. title(monkey);
  41. disp(['---- ' monkey ' | shape ----']);
  42. [~,p,~,st] = ttest(D(:,1),D(:,2));
  43. disp([monkey ', target vs non-target, p=' num2str(p) ', t=' num2str(st.tstat) ', df=' num2str(st.df)]);
  44. figure(f1b); subplot(2,3,mi+1); hold on;
  45. bar([1 2],[mean(D(:,1)) mean(D(:,2))]);
  46. errorbar([1 2],[mean(D(:,1)) mean(D(:,2))],...
  47. [std(D(:,1))./sqrt(size(D,1)) std(D(:,2))./sqrt(size(D,1))],...
  48. 'LineStyle','none','Color','k')
  49. x = ones(size(D,1),1); x = x + (randi(10,length(x),1)-5)/30;
  50. cx = [];
  51. for l=1:2; cx(:,l) = x + 1*(l-1); end
  52. incr = D(:,2)>D(:,1);
  53. plot(cx(incr,:)',D(incr,:)','Color',[.4 .4 .4]); hold all;
  54. plot(cx(~incr,:)',D(~incr,:)','Color',[.8 .8 .8]);
  55. for l=1:size(D,2)
  56. scatter(cx(incr,l),D(incr,l),20,[.4 .4 .4],'f');
  57. scatter(cx(~incr,l),D(~incr,l),20,[.8 .8 .8],'f');
  58. end
  59. title(monkey);
  60. set(gca,'ylim',[-0.1 0.2]);
  61. figure(f1); subplot(2,3,mi+4);
  62. [D, q] = make_plot(env_t,distmod,tracesLUT.shapeswitch,'Shape');
  63. DShape{mi,2}=D;
  64. DShape_q{mi,2}=q;
  65. ylabel('distractor modulation');
  66. title(monkey);
  67. [~,p,~,st] = ttest(D(:,1),D(:,2));
  68. disp([monkey ', distractor vs non-target, p=' num2str(p) ', t=' num2str(st.tstat) ', df=' num2str(st.df)]);
  69. figure(f1b); subplot(2,3,mi+4); hold on;
  70. bar([1 2],[mean(D(:,1)) mean(D(:,2))]);
  71. errorbar([1 2],[mean(D(:,1)) mean(D(:,2))],...
  72. [std(D(:,1))./sqrt(size(D,1)) std(D(:,2))./sqrt(size(D,1))],...
  73. 'LineStyle','none','Color','k')
  74. x = ones(size(D,1),1); x = x + (randi(10,length(x),1)-5)/30;
  75. cx = [];
  76. for l=1:2; cx(:,l) = x + 1*(l-1); end
  77. incr = D(:,2)>D(:,1);
  78. plot(cx(incr,:)',D(incr,:)','Color',[.8 .8 .8]); hold all;
  79. plot(cx(~incr,:)',D(~incr,:)','Color',[.4 .4 .4]);
  80. for l=1:size(D,2)
  81. scatter(cx(incr,l),D(incr,l),20,[.8 .8 .8],'f');
  82. scatter(cx(~incr,l),D(~incr,l),20,[.4 .4 .4],'f');
  83. end
  84. title(monkey);
  85. set(gca,'ylim',[-0.1 0.05]);
  86. %% do the same on color
  87. figure(f2); subplot(2,3,mi+1);
  88. [D, q] = make_plot(env_t,targmod,tracesLUT.colorswitch,'Color');
  89. DColor{mi,1}=D;
  90. DColor_q{mi,1}=q;
  91. ylabel('target modulation');
  92. title(monkey);
  93. disp(['---- ' monkey ' | color ----']);
  94. [~,p,~,st] = ttest(D(:,1),D(:,2));
  95. disp([monkey ', target vs non-target, p=' num2str(p) ', t=' num2str(st.tstat) ', df=' num2str(st.df)]);
  96. figure(f2b); subplot(2,3,mi+1); hold on;
  97. bar([1 2],[mean(D(:,1)) mean(D(:,2))]);
  98. errorbar([1 2],[mean(D(:,1)) mean(D(:,2))],...
  99. [std(D(:,1))./sqrt(size(D,1)) std(D(:,2))./sqrt(size(D,1))],...
  100. 'LineStyle','none','Color','k')
  101. x = ones(size(D,1),1); x = x + (randi(10,length(x),1)-5)/30;
  102. cx = [];
  103. for l=1:2; cx(:,l) = x + 1*(l-1); end
  104. incr = D(:,2)>D(:,1);
  105. plot(cx(incr,:)',D(incr,:)','Color',[.4 .4 .4]); hold all;
  106. plot(cx(~incr,:)',D(~incr,:)','Color',[.8 .8 .8]);
  107. for l=1:size(D,2)
  108. scatter(cx(incr,l),D(incr,l),20,[.4 .4 .4],'f');
  109. scatter(cx(~incr,l),D(~incr,l),20,[.8 .8 .8],'f');
  110. end
  111. title(monkey);
  112. set(gca,'ylim',[-0.1 0.2]);
  113. figure(f2); subplot(2,3,mi+4);
  114. [D, q] = make_plot(env_t,distmod,tracesLUT.colorswitch,'Color');
  115. DColor{mi,2}=D;
  116. DColor_q{mi,2}=q;
  117. ylabel('distractor modulation');
  118. title(monkey);
  119. [~,p,~,st] = ttest(D(:,1),D(:,2));
  120. disp([monkey ', distractor vs non-target, p=' num2str(p) ', t=' num2str(st.tstat) ', df=' num2str(st.df)]);
  121. figure(f2b); subplot(2,3,mi+4); hold on;
  122. bar([1 2],[mean(D(:,1)) mean(D(:,2))]);
  123. errorbar([1 2],[mean(D(:,1)) mean(D(:,2))],...
  124. [std(D(:,1))./sqrt(size(D,1)) std(D(:,2))./sqrt(size(D,1))],...
  125. 'LineStyle','none','Color','k')
  126. x = ones(size(D,1),1); x = x + (randi(10,length(x),1)-5)/30;
  127. cx = [];
  128. for l=1:2; cx(:,l) = x + 1*(l-1); end
  129. incr = D(:,2)>D(:,1);
  130. plot(cx(incr,:)',D(incr,:)','Color',[.8 .8 .8]); hold all;
  131. plot(cx(~incr,:)',D(~incr,:)','Color',[.4 .4 .4]);
  132. for l=1:size(D,2)
  133. scatter(cx(incr,l),D(incr,l),20,[.8 .8 .8],'f');
  134. scatter(cx(~incr,l),D(~incr,l),20,[.4 .4 .4],'f');
  135. end
  136. title(monkey);
  137. set(gca,'ylim',[-0.1 0.05]);
  138. end
  139. %% Now do the same thing on the pooled data
  140. %% plot the effect of shape change on target modulation
  141. %f0 = figure; set(gcf,'Position',[216 492 411 606]);
  142. figure(f1); subplot(2,3,1);
  143. DD = [DShape{1,1};DShape{2,1}];
  144. q = [DShape_q{1,1};DShape_q{2,1}];
  145. make_plot_pooled(q, env_t, 'Shape')
  146. ylabel('target modulation');
  147. title('BOTH monkeys');
  148. disp('---- BOTH | shape ----');
  149. [~,p,~,st] = ttest(DD(:,1),DD(:,2));
  150. disp(['BOTH, target vs non-target, p=' num2str(p) ...
  151. ', t=' num2str(st.tstat) ', df=' num2str(st.df)]);
  152. suptitle('Effect of Shape-change on neural activity');
  153. %f0b = figure; set(gcf,'Position',[100 100 250 500]);
  154. figure(f1b); subplot(2,3,1); hold on;
  155. bar([1 2],[mean(DD(:,1)) mean(DD(:,2))]);
  156. errorbar([1 2],[mean(DD(:,1)) mean(DD(:,2))],...
  157. [std(DD(:,1))./sqrt(size(DD,1)) std(DD(:,2))./sqrt(size(DD,1))],...
  158. 'LineStyle','none','Color','k')
  159. x = ones(size(DD,1),1); x = x + (randi(10,length(x),1)-5)/30;
  160. cx = [];
  161. for l=1:2; cx(:,l) = x + 1*(l-1); end
  162. incr = DD(:,2)>DD(:,1);
  163. plot(cx(incr,:)',DD(incr,:)','Color',[.4 .4 .4]); hold all;
  164. plot(cx(~incr,:)',DD(~incr,:)','Color',[.8 .8 .8]);
  165. for l=1:size(DD,2)
  166. scatter(cx(incr,l),DD(incr,l),20,[.4 .4 .4],'f');
  167. scatter(cx(~incr,l),DD(~incr,l),20,[.8 .8 .8],'f');
  168. end
  169. title('BOTH');
  170. set(gca,'ylim',[-0.1 0.2]);
  171. suptitle('Effect of Shape-change on neural activity');
  172. figure(f1); subplot(2,3,4);
  173. DD = [DShape{1,2};DShape{2,2}];
  174. q = [DShape_q{1,2};DShape_q{2,2}];
  175. make_plot_pooled(q, env_t, 'Shape')
  176. ylabel('distractor modulation');
  177. title('BOTH monkeys');
  178. [~,p,~,st] = ttest(DD(:,1),DD(:,2));
  179. disp(['BOTH, distractor vs non-target, p=' num2str(p) ...
  180. ', t=' num2str(st.tstat) ', df=' num2str(st.df)]);
  181. figure(f1b); subplot(2,3,4); hold on;
  182. bar([1 2],[mean(DD(:,1)) mean(DD(:,2))]);
  183. errorbar([1 2],[mean(DD(:,1)) mean(DD(:,2))],...
  184. [std(DD(:,1))./sqrt(size(DD,1)) std(DD(:,2))./sqrt(size(DD,1))],...
  185. 'LineStyle','none','Color','k')
  186. x = ones(size(DD,1),1); x = x + (randi(10,length(x),1)-5)/30;
  187. cx = [];
  188. for l=1:2; cx(:,l) = x + 1*(l-1); end
  189. incr = DD(:,2)>DD(:,1);
  190. plot(cx(incr,:)',DD(incr,:)','Color',[.8 .8 .8]); hold all;
  191. plot(cx(~incr,:)',DD(~incr,:)','Color',[.4 .4 .4]);
  192. for l=1:size(DD,2)
  193. scatter(cx(incr,l),DD(incr,l),20,[.8 .8 .8],'f');
  194. scatter(cx(~incr,l),DD(~incr,l),20,[.4 .4 .4],'f');
  195. end
  196. title('BOTH');
  197. set(gca,'ylim',[-0.1 0.05]);
  198. %% do the same on color
  199. %f00 = figure; set(gcf,'Position',[216 492 411 606]);
  200. figure(f2); subplot(2,3,1);
  201. DD = [DColor{1,1};DColor{2,1}];
  202. q = [DColor_q{1,1};DColor_q{2,1}];
  203. make_plot_pooled(q, env_t, 'Color')
  204. ylabel('target modulation');
  205. title('BOTH');
  206. disp('---- BOTH | color ----');
  207. [~,p,~,st] = ttest(DD(:,1),DD(:,2));
  208. disp(['BOTH, target vs non-target, p=' num2str(p) ...
  209. ', t=' num2str(st.tstat) ', df=' num2str(st.df)]);
  210. suptitle('Effect of Color-change on neural activity');
  211. %f00b = figure; set(gcf,'Position',[100 100 250 500]);
  212. figure(f2b); subplot(2,3,1); hold on;
  213. bar([1 2],[mean(DD(:,1)) mean(DD(:,2))]);
  214. errorbar([1 2],[mean(DD(:,1)) mean(DD(:,2))],...
  215. [std(DD(:,1))./sqrt(size(DD,1)) std(DD(:,2))./sqrt(size(DD,1))],...
  216. 'LineStyle','none','Color','k')
  217. x = ones(size(DD,1),1); x = x + (randi(10,length(x),1)-5)/30;
  218. cx = [];
  219. for l=1:2; cx(:,l) = x + 1*(l-1); end
  220. incr = DD(:,2)>DD(:,1);
  221. plot(cx(incr,:)',DD(incr,:)','Color',[.4 .4 .4]); hold all;
  222. plot(cx(~incr,:)',DD(~incr,:)','Color',[.8 .8 .8]);
  223. for l=1:size(DD,2)
  224. scatter(cx(incr,l),DD(incr,l),20,[.4 .4 .4],'f');
  225. scatter(cx(~incr,l),DD(~incr,l),20,[.8 .8 .8],'f');
  226. end
  227. title('BOTH');
  228. set(gca,'ylim',[-0.1 0.2]);
  229. suptitle('Effect of Color-change on neural activity');
  230. figure(f2); subplot(2,3,4);
  231. DD = [DColor{1,2};DColor{2,2}];
  232. q = [DColor_q{1,2};DColor_q{2,2}];
  233. make_plot_pooled(q, env_t, 'Color')
  234. ylabel('distractor modulation');
  235. title('BOTH');
  236. [~,p,~,st] = ttest(DD(:,1),DD(:,2));
  237. disp(['BOTH, distractor vs non-target, p=' num2str(p) ...
  238. ', t=' num2str(st.tstat) ', df=' num2str(st.df)]);
  239. figure(f2b); subplot(2,3,4); hold on;
  240. bar([1 2],[mean(DD(:,1)) mean(DD(:,2))]);
  241. errorbar([1 2],[mean(DD(:,1)) mean(DD(:,2))],...
  242. [std(DD(:,1))./sqrt(size(DD,1)) std(DD(:,2))./sqrt(size(DD,1))],...
  243. 'LineStyle','none','Color','k')
  244. x = ones(size(DD,1),1); x = x + (randi(10,length(x),1)-5)/30;
  245. cx = [];
  246. for l=1:2; cx(:,l) = x + 1*(l-1); end
  247. incr = DD(:,2)>DD(:,1);
  248. plot(cx(incr,:)',DD(incr,:)','Color',[.8 .8 .8]); hold all;
  249. plot(cx(~incr,:)',DD(~incr,:)','Color',[.4 .4 .4]);
  250. for l=1:size(DD,2)
  251. scatter(cx(incr,l),DD(incr,l),20,[.8 .8 .8],'f');
  252. scatter(cx(~incr,l),DD(~incr,l),20,[.4 .4 .4],'f');
  253. end
  254. title('BOTH');
  255. set(gca,'ylim',[-0.1 0.05]);
  256. end
  257. function [D , q] = make_plot(env_t,data,selector,featurename)
  258. yellow = [247 148 29]./255;
  259. blue = [27 117 188]./255;
  260. cols = [blue; yellow];
  261. falpha = 0.4;
  262. hold off
  263. p = [];
  264. win_idx = find(env_t>0.15 & env_t<0.20);
  265. D = [];
  266. for featureswitch = [0 1]
  267. incl = selector==featureswitch;
  268. q{featureswitch+1} = data(incl,:);
  269. mn = mean(q{featureswitch+1});
  270. sem = std(q{featureswitch+1})./sqrt(sum(incl));
  271. % also prepare for some stats
  272. D(:,featureswitch+1) = mean(data(incl,win_idx),2);
  273. t2 = [env_t, fliplr(env_t)];
  274. inBetween = [mn+sem, fliplr(mn-sem)];
  275. fill(t2*1e3, inBetween, 'g','LineStyle','none','FaceColor',...
  276. cols(featureswitch+1,:),'FaceAlpha',falpha); hold all
  277. p(end+1) = plot(env_t*1e3,mn,'Color',cols(featureswitch+1,:));
  278. end
  279. legend(p,{[featurename '-same'],[featurename '-swap']},'Location','southwest');
  280. xlabel('time(ms)');
  281. plot([env_t(1)*1e3 env_t(end)*1e3],[0 0],'k-')
  282. set(gca,'xlim',[-50 250]);
  283. end
  284. function make_plot_pooled(q, env_t, featurename)
  285. yellow = [247 148 29]./255;
  286. blue = [27 117 188]./255;
  287. cols = [blue; yellow];
  288. falpha = 0.4;
  289. hold off
  290. p = [];
  291. for featureswitch = [0 1]
  292. mn = mean(q{featureswitch+1});
  293. sem = std(q{featureswitch+1})./sqrt(sum(size(q{featureswitch+1},1)));
  294. t2 = [env_t, fliplr(env_t)];
  295. inBetween = [mn+sem, fliplr(mn-sem)];
  296. fill(t2*1e3, inBetween, 'g','LineStyle','none','FaceColor',...
  297. cols(featureswitch+1,:),'FaceAlpha',falpha); hold all
  298. p(end+1) = plot(env_t*1e3,mn,'Color',cols(featureswitch+1,:));
  299. end
  300. legend(p,{[featurename '-same'],[featurename '-swap']},'Location','southwest');
  301. xlabel('time(s)');
  302. plot([env_t(1)*1e3 env_t(end)*1e3],[0 0],'k-')
  303. set(gca,'xlim',[-50 250]);
  304. end