V1V1_spikes_ms1p.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. %% Population analysis of the straightforward MS data SPIKES ============
  2. % no MS vs MS @ 150ms, visual stimulus: homogenous texture
  3. % ------------------------------------------------------------
  4. % Loads an overview table of data to potentially include, imports the
  5. % bandpass filtered data and saves it together in a population data file.
  6. % Once this has been done, it can also directly load this file and work
  7. % with that.
  8. % single pulses
  9. presaved = true; %
  10. set_spike_window = false; % allows to set the spike thresholding windows
  11. MeanAlreadySubtracted = true;
  12. %% load info ============================================================
  13. load(fullfile(fld.data,'V1V1.mat'));
  14. if ~set_spike_window
  15. load(fullfile(fld.data,'V1V1_spikes.mat'));
  16. end
  17. %% load data ============================================================
  18. fprintf('Loading data..');
  19. if ~presaved
  20. curr_sel = 0;
  21. for ff=1:length(V1V1.Day)
  22. indstr = V1V1.indeces(ff);
  23. sep = find(indstr{1}=='_'==1);
  24. sel_files = ...
  25. [str2double(indstr{1}(1:sep-1)) str2double(indstr{1}(sep+1:end))];
  26. if curr_sel ~= sel_files(1) % only load files once
  27. curr_sel=sel_files(1);
  28. % Wav2 = CH1-16
  29. % Wave = CH17-32
  30. if MeanAlreadySubtracted
  31. % << artefact removal in raw
  32. cd(fullfile(fld.data,'BANDPASS','BP3','500to5000'));
  33. else
  34. % << first BP version (no artefact removal in raw)
  35. cd(fullfile(fld.data,'BANDPASS','BP','500to5000'));
  36. end
  37. CHMap = [1:16;17:32];
  38. CHi = [ones(1,16) ones(1,16).*2 ; 1:16 1:16];
  39. for df=1:2
  40. fprintf(['Loading ' filenames{sel_files(df)} '\n']);
  41. load(filenames{sel_files(df)},'Data')
  42. D(df)=Data; clear Data; %#ok<*SAGROW>
  43. t_vis = D(df).Time+0.150;
  44. end
  45. end
  46. % Resave selected channels
  47. % use 'CHi'
  48. sC = V1V1.rec_channel(ff);
  49. V1_V1(ff).info = V1V1(ff,:);
  50. V1_V1(ff).ms_trials = ...
  51. D(CHi(1,sC)).Trials(:,5)==1 & D(CHi(1,sC)).Trials(:,7)==1;
  52. V1_V1(ff).ms_i = (find(V1_V1(ff).ms_trials==1))';
  53. V1_V1(ff).noms_trials = ...
  54. D(CHi(1,sC)).Trials(:,5)==1 & D(CHi(1,sC)).Trials(:,7)==2;
  55. V1_V1(ff).noms_i = (find(V1_V1(ff).noms_trials==1))';
  56. V1_V1(ff).t_vis = t_vis;
  57. V1_V1(ff).d = D(CHi(1,sC)).Signal(:,CHi(2,sC),:);
  58. end
  59. cd(fld.scripts);
  60. V1_V1_info = V1V1;
  61. if MeanAlreadySubtracted
  62. save(fullfile(fld.data,'V1V1_Selected2_1p'),...
  63. 'V1_V1','V1_V1_info','-v7.3');
  64. else
  65. save(fullfile(fld.data,'V1V1_Selected_1p'),...
  66. 'V1_V1','V1_V1_info','-v7.3');
  67. end
  68. else
  69. if MeanAlreadySubtracted
  70. load(fullfile(fld.data,'V1V1_Selected2_1p.mat'));
  71. else
  72. load(fullfile(fld.data,'V1V1_Selected_1p.mat'));
  73. end
  74. end
  75. fprintf('DONE!\n');
  76. %% Set the spike thresholding window ====================================
  77. if set_spike_window
  78. % select a channel
  79. sC = input(['Which data? (max ' num2str(length(V1_V1)) '): ']);
  80. msw = [0.148 0.152];
  81. MSmask = V1_V1(sC).t_vis>msw(1) & V1_V1(sC).t_vis<msw(2);
  82. figure
  83. subplot(2,1,1);hold on;
  84. for i=V1_V1(sC).noms_i
  85. plot(V1_V1(sC).t_vis,V1_V1(sC).d(:,:,i));
  86. end
  87. set(gca,'xlim',[-.05 0.3],'ylim',[-500 400])
  88. title(['All No MS Trials DataNum ' num2str(sC) ])
  89. subplot(2,1,2);hold on;
  90. for i=V1_V1(sC).ms_i
  91. V1_V1(sC).md(:,:,i)=V1_V1(sC).d(:,:,i);
  92. V1_V1(sC).md(MSmask,:,i)=0;
  93. plot(V1_V1(sC).t_vis,V1_V1(sC).md(:,:,i));
  94. end
  95. set(gca,'xlim',[-.05 0.3],'ylim',[-500 400])
  96. title(['All MS Trials DataNum ' num2str(sC) ])
  97. % set spike threshold window
  98. if isfield(V1_V1(sC),'TH') && ~isempty(V1_V1(sC).TH)
  99. TH = V1_V1(sC).TH;
  100. else
  101. V1_V1(sC).TH=[];
  102. while isempty(V1_V1(sC).TH)
  103. TH = input('Set spike threshold window: ');
  104. % plot the histograms
  105. PosNeg = -1; % neg peak detection
  106. spikes.ms=[];spikes.noms=[];
  107. n=0;
  108. for i=V1_V1(sC).noms_i(1:end)
  109. n=n+1;
  110. y = V1_V1(sC).d(:,:,i);
  111. [yp,xp] = findpeaks(double(PosNeg.*y),V1_V1(sC).t_vis,...
  112. 'MinPeakHeight',TH(1));
  113. xp(yp>TH(2))=[];
  114. yp(yp>TH(2))=[];
  115. spikes.noms=[spikes.noms; xp' yp ones(size(yp))*n];
  116. end
  117. n=0;
  118. for i=V1_V1(sC).ms_i(1:end)
  119. n=n+1;
  120. y = V1_V1(sC).md(:,:,i);
  121. [yp,xp] = findpeaks(double(PosNeg.*y),V1_V1(sC).t_vis,...
  122. 'MinPeakHeight',TH(1));
  123. xp(yp>TH(2))=[];
  124. yp(yp>TH(2))=[];
  125. spikes.ms=[spikes.ms; xp' yp ones(size(yp))*n];
  126. end
  127. BinSpecs=[-200 5 400]./1000;
  128. [spikes.noms_n, spikes.noms_bin] = ...
  129. hist(spikes.noms(:,1),BinSpecs(1):BinSpecs(2):BinSpecs(3));
  130. spikes.noms_n=spikes.noms_n./length(V1_V1(sC).noms_i);
  131. [spikes.ms_n, spikes.ms_bin] = hist(spikes.ms(:,1),...
  132. BinSpecs(1):BinSpecs(2):BinSpecs(3));
  133. spikes.ms_n=spikes.ms_n./length(V1_V1(sC).ms_i);
  134. figure;
  135. % Histograms -------
  136. subplot(2,3,4);hold on;
  137. bar(spikes.noms_bin(2:end-1),spikes.noms_n(2:end-1),'FaceColor','k','Barwidth',1)
  138. peak = max(spikes.noms_n(spikes.noms_bin>0 & spikes.noms_bin<0.150));
  139. plot([msw(1) msw(1)],[0 1000],'b--');
  140. plot([msw(2) msw(2)],[0 1000],'b--')
  141. set(gca,'xlim',[-0.1 0.350],'ylim',[0 peak*1.1])
  142. title('No MS');
  143. subplot(2,3,5);hold on;
  144. bar(spikes.ms_bin(2:end-1),spikes.ms_n(2:end-1),'FaceColor','r','EdgeColor','r','Barwidth',1)
  145. peak = max(spikes.ms_n(spikes.ms_bin>0 & spikes.ms_bin<0.150));
  146. plot([msw(1) msw(1)],[0 1000],'b--');
  147. plot([msw(2) msw(2)],[0 1000],'b--')
  148. set(gca,'xlim',[-0.1 0.350],'ylim',[0 peak*1.1])
  149. title('MS');
  150. % Raster plots ------
  151. subplot(2,3,1);hold on;
  152. for i=1:length(V1_V1(sC).noms_i)
  153. s=spikes.noms(:,3)==i;
  154. plot(spikes.noms(s,1),spikes.noms(s,3),'ko',...
  155. 'MarkerSize',3,'MarkerFaceColor','k')
  156. end
  157. plot([msw(1) msw(1)],[0 1000],'b--');
  158. plot([msw(2) msw(2)],[0 1000],'b--')
  159. set(gca,'xlim',[-0.1 0.35],'ylim',[0 i]);
  160. title('No MS');
  161. subplot(2,3,2);hold on
  162. for i=1:length(V1_V1(sC).ms_i)
  163. s=spikes.ms(:,3)==i;
  164. plot(spikes.ms(s,1),spikes.ms(s,3),'ro',...
  165. 'MarkerSize',3,'MarkerFaceColor','r')
  166. end
  167. plot([msw(1) msw(1)],[0 1000],'b--');
  168. plot([msw(2) msw(2)],[0 1000],'b--')
  169. set(gca,'xlim',[-0.1 0.35],'ylim',[0 i]);
  170. title('MS');
  171. % 2 histograms overlaid -----
  172. subplot(2,3,3);hold on;
  173. bar(spikes.noms_bin(2:end-1),spikes.noms_n(2:end-1),...
  174. 'EdgeColor','k','LineWidth',2,'FaceColor',...
  175. 'none','Barwidth',1)
  176. bar(spikes.ms_bin(2:end-1),spikes.ms_n(2:end-1),...
  177. 'EdgeColor','r','LineWidth',2,'FaceColor',...
  178. 'none','Barwidth',1)
  179. plot([msw(1) msw(1)],[0 1000],'b--');
  180. plot([msw(2) msw(2)],[0 1000],'b--')
  181. legend({'No MS','MS'})
  182. set(gca,'xlim',[-0.05 0.350],'ylim',[0 peak*1.1])
  183. title('No Ms vs. MS');
  184. % Difference zoomed in ------
  185. subplot(2,3,6);hold on;
  186. bar(spikes.noms_bin(2:end-1),...
  187. spikes.ms_n(2:end-1)-spikes.noms_n(2:end-1),...
  188. 'EdgeColor','k','FaceColor','k','Barwidth',1)
  189. plot(spikes.noms_bin(2:end-1),...
  190. smooth(spikes.ms_n(2:end-1)-spikes.noms_n(2:end-1),5),...
  191. 'r','LineWidth',1)
  192. plot([msw(1) msw(1)],[0 1000],'b--');
  193. plot([msw(2) msw(2)],[0 1000],'b--')
  194. set(gca,'xlim',[0.100 0.350],'ylim',[-0.08 0.3])
  195. title('Difference MS-NoMS');
  196. % ask to approve
  197. keepTH = input('Keep this spike window? (y/n): ','s');
  198. if strcmp(keepTH,'y') || strcmp(keepTH,'Y')
  199. V1_V1(sC).TH = TH;
  200. close all;
  201. end
  202. end
  203. end
  204. else
  205. V1V1.TH1 = [V1V1_info{2:end,13}]';
  206. V1V1.TH2 = [V1V1_info{2:end,14}]';
  207. for sC = 1:size(V1_V1,2)
  208. V1_V1(sC).TH = [V1V1.TH1(sC) V1V1.TH2(sC)];
  209. end
  210. end
  211. %% Average ==============================================================
  212. fprintf('Processing spikes\n');
  213. if ~presaved
  214. TrialSel = [...
  215. 3 10 40 10 40;...
  216. 6 1 70 1 55;...
  217. 10 70 215 70 215 ];
  218. warning off %#ok<*WNOFF>
  219. msw = [0.148 0.152];
  220. MaskStimArtefact = false;
  221. MaskStimBinOnly =true; % extrapolates previous timepoint
  222. BinSpecs=[-200 5 400]./1000;
  223. PosNeg = -1; % neg peak detection
  224. psth_nms=[];psth_ms=[];
  225. fprintf('Making PSTHs\n')
  226. for sC = 1:length(V1_V1)
  227. fprintf([num2str(sC) '\n']);
  228. spk(sC).ms=[];spk(sC).noms=[];
  229. if ismember(sC,TrialSel(:,1))
  230. r=find(TrialSel(:,1)==sC);
  231. nm_ti = TrialSel(r,2:3);
  232. m_ti = TrialSel(r,4:5);
  233. else
  234. nm_ti = [1 length(V1_V1(sC).noms_i)];
  235. m_ti = [1 length(V1_V1(sC).ms_i)];
  236. end
  237. n=0;
  238. % subtract average artefact shape ------
  239. MSTi = V1_V1(sC).ms_i(m_ti(1):m_ti(2));
  240. av_msTrace = nanmean(V1_V1(sC).d(:,:,MSTi),3);
  241. SubtractAverage=false;
  242. % --------------------------------------
  243. for i=V1_V1(sC).noms_i(nm_ti(1):nm_ti(2))
  244. n=n+1;
  245. y = V1_V1(sC).d(:,:,i);
  246. [yp,xp] = findpeaks(double(PosNeg.*y),V1_V1(sC).t_vis,...
  247. 'MinPeakHeight',V1_V1(sC).TH(1));
  248. xp(yp>V1_V1(sC).TH(2))=[];
  249. yp(yp>V1_V1(sC).TH(2))=[];
  250. spk(sC).noms=[spk(sC).noms; xp' yp ones(size(yp))*n];
  251. end
  252. n=0;
  253. for i=V1_V1(sC).ms_i(m_ti(1):m_ti(2))
  254. n=n+1;
  255. if SubtractAverage
  256. y = V1_V1(sC).d(:,:,i)-av_msTrace;
  257. if MaskStimArtefact
  258. MSmask = V1_V1(sC).t_vis>msw(1) & V1_V1(sC).t_vis<msw(2);
  259. y(MSmask,:,:) = 0;
  260. end
  261. else
  262. y = V1_V1(sC).d(:,:,i); %use masked trace
  263. end
  264. [yp,xp] = findpeaks(double(PosNeg.*y),V1_V1(sC).t_vis,...
  265. 'MinPeakHeight',V1_V1(sC).TH(1));
  266. xp(yp>V1_V1(sC).TH(2))=[];
  267. yp(yp>V1_V1(sC).TH(2))=[];
  268. % remove spikes during pulse window
  269. yp(xp>msw(1) & xp<msw(2))=[];
  270. xp(xp>msw(1) & xp<msw(2))=[];
  271. spk(sC).ms=[spk(sC).ms; xp' yp ones(size(yp))*n];
  272. end
  273. % sliding window approach ----
  274. SlidWin.width = 0.010;
  275. SlidWin.step = 0.001;
  276. SlidWin.Min = -0.200;
  277. SlidWin.Max = 0.350;
  278. spk(sC).noms_n = []; spk(sC).noms_bin = [];
  279. for tstep = (SlidWin.Min-(SlidWin.width/2)):...
  280. SlidWin.step:(SlidWin.Max-(SlidWin.width/2))
  281. t1 = tstep; t2 = tstep+SlidWin.width;
  282. y=sum(spk(sC).noms(:,1) >= t1 & spk(sC).noms(:,1) <= t2)/...
  283. ( (t2-t1)*max(spk(sC).noms(:,3)));
  284. spk(sC).noms_bin=[spk(sC).noms_bin tstep];
  285. spk(sC).noms_n=[spk(sC).noms_n; y];
  286. end
  287. spk(sC).ms_n = []; spk(sC).ms_bin = [];
  288. for tstep = (SlidWin.Min-(SlidWin.width/2)):...
  289. SlidWin.step:(SlidWin.Max-(SlidWin.width/2))
  290. t1 = tstep; t2 = tstep+SlidWin.width;
  291. if t1>msw(1) && t1<=msw(2); t1 = msw(2); end
  292. if t2>=msw(1) && t2<msw(2); t2 = msw(1); end
  293. if t1<msw(1) && t2>=msw(2); t2 = msw(1); end
  294. if abs(t1-msw(1))<SlidWin.step
  295. % don't change y
  296. else
  297. y=sum(spk(sC).ms(:,1) >= t1 & spk(sC).ms(:,1) <= t2)/...
  298. ((t2-t1)*max(spk(sC).ms(:,3)));
  299. end
  300. spk(sC).ms_bin=[spk(sC).ms_bin tstep];
  301. spk(sC).ms_n=[spk(sC).ms_n; y];
  302. end
  303. psth_nms=[psth_nms;spk(sC).noms_n']; %#ok<*AGROW>
  304. psth_ms=[psth_ms;spk(sC).ms_n'];
  305. end
  306. if MeanAlreadySubtracted
  307. save(fullfile(fld.data,'V1V1_spikes'),...
  308. 'spk','psth_nms','psth_ms', 'V1V1');
  309. else
  310. save(fullfile(fld.data,'V1V1_spikes2'),...
  311. 'spk','psth_nms','psth_ms', 'V1V1');
  312. end
  313. fprintf('DONE!\n')
  314. else
  315. msw = [0.148 0.152];
  316. if MeanAlreadySubtracted
  317. load(fullfile(fld.data,'V1V1_spikes.mat'));
  318. else
  319. load(fullfile(fld.data,'V1V1_spikes2.mat'));
  320. end
  321. fprintf('DONE!\n')
  322. end
  323. %% subtract baseline, peak normalize & plot =============================
  324. t=spk(1).ms_bin;
  325. for s=1:size(spk,2)
  326. y1=spk(s).noms_n; y2=spk(s).ms_n;
  327. y1_bl= y1-nanmean([y1(t>-0.100 & t<0); y2(t>-0.100 & t<0)]);
  328. y2_bl= y2-nanmean([y1(t>-0.100 & t<0); y2(t>-0.100 & t<0)]);
  329. yp = max(y1_bl(t>0 & t<0.100));
  330. y1n=y1_bl./yp; y2n=y2_bl./yp;
  331. spk(s).noms_n2=y1n;
  332. spk(s).ms_n2=y2n;
  333. end
  334. for s=1:size(spk,2)
  335. psth_nms(s,:) = spk(s).noms_n2; % Normalized
  336. %psth_nms(s,:) = spk(s).noms_n;
  337. psth_ms(s,:) = spk(s).ms_n2; % Normalized
  338. %psth_ms(s,:) = spk(s).ms_n;
  339. end
  340. %% plot the traces ======================================================
  341. % select a subset of combinations
  342. sel = V1V1.ManSel==1;
  343. msw = [0.148 0.152];
  344. % sel = V1V1.current>0; % all
  345. N=sum(sel);
  346. fprintf(['Number of stim-rec combinations in average: ' num2str(N) '\n']);
  347. figure;
  348. % Histograms -------
  349. subplot(2,2,1);hold on;
  350. BL_nms = mean2(psth_nms(sel,spk(1).noms_bin(2:end-1)<0 & ...
  351. spk(1).noms_bin(2:end-1)>-0.100));
  352. mPSTH_nms = mean(psth_nms(sel,2:end-1),1);%-BL_nms;
  353. sePSTH_nms = std(psth_nms(sel,2:end-1),1)./sqrt(length(sel));%-BL_nms;
  354. bar(spk(1).noms_bin(2:end-1),mPSTH_nms,'FaceColor','k','Barwidth',1)
  355. plot([msw(1) msw(1)],[-100 100],'b--');
  356. plot([msw(2) msw(2)],[-100 100],'b--')
  357. set(gca,'xlim',[-0.05 0.350],'ylim',[-0.1 1.1])
  358. title('No MS');
  359. text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
  360. subplot(2,2,3);hold on;
  361. BL_ms = mean2(psth_ms(sel,spk(1).ms_bin(2:end-1)<0 & ...
  362. spk(1).ms_bin(2:end-1)>-0.100));
  363. mPSTH_ms = mean(psth_ms(sel,2:end-1),1);%-BL_ms;
  364. sePSTH_ms = std(psth_ms(sel,2:end-1),1)./sqrt(length(sel));%-BL_nms;
  365. bar(spk(1).ms_bin(2:end-1),mPSTH_ms,'FaceColor','r',...
  366. 'EdgeColor','r','Barwidth',1)
  367. plot([msw(1) msw(1)],[-100 100],'b--');
  368. plot([msw(2) msw(2)],[-100 100],'b--')
  369. set(gca,'xlim',[-0.05 0.350],'ylim',[-0.1 1.1])
  370. title('MS');
  371. text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
  372. % 2 histograms overlaid -----
  373. subplot(2,2,2);hold on;
  374. plot(spk(1).noms_bin(2:end-1),mPSTH_nms,'Color','k','LineWidth',2)
  375. plot(spk(1).ms_bin(2:end-1),mPSTH_ms,'Color','r','LineWidth',2)
  376. plot([msw(1) msw(1)],[-100 100],'b--');
  377. plot([msw(2) msw(2)],[-100 100],'b--')
  378. legend({'No MS','MS'})
  379. set(gca,'xlim',[-0.05 0.350],'ylim',[-0.1 1.1])
  380. title('No Ms vs. MS');
  381. text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
  382. % Difference zoomed in ------
  383. subplot(2,2,4);hold on;
  384. bar(spk(1).noms_bin(2:end-1),mPSTH_ms-mPSTH_nms,...
  385. 'EdgeColor','k','FaceColor','k','Barwidth',1)
  386. plot([msw(1) msw(1)],[-100 100],'b--');
  387. plot([msw(2) msw(2)],[-100 100],'b--')
  388. set(gca,'xlim',[0.100 0.30],'ylim',[-0.20 0.3])
  389. title('Difference MS-NoMS');
  390. text(0.26,0.20,['N = ' num2str(N)],'fontsize',12);
  391. print_figure('Fig2D' ,[0 0 32 20],fullfile(fld.figs,'FIG_2'),save_figs);
  392. cd(fld.scripts);
  393. %% sem-plot =============================================================
  394. figure;
  395. smw = 7;
  396. subplot(1,3,1);hold on;
  397. plot(spk(1).noms_bin(2:end-1),smooth(mPSTH_nms,smw),'k','LineWidth',2)
  398. plot(spk(1).ms_bin(2:end-1),smooth(mPSTH_ms,smw),'r','LineWidth',2)
  399. plot([-100 100],[0 0],'k');
  400. plot([msw(1) msw(1)],[-100 100],'b--');
  401. plot([msw(2) msw(2)],[-100 100],'b--')
  402. legend({'No MS','MS'})
  403. set(gca,'xlim',[-0.05 0.350],'ylim',[-.1 1.1])
  404. title('No Ms vs. MS');
  405. text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
  406. subplot(1,3,2);hold on;
  407. x=spk(1).noms_bin(2:end-1);
  408. y=[mPSTH_nms-sePSTH_nms; mPSTH_nms; mPSTH_nms+sePSTH_nms];
  409. px=[x,fliplr(x)];
  410. py=[y(1,:), fliplr(y(3,:))];
  411. patch(px,smooth(py,smw),1,'FaceColor','k','FaceAlpha',0.3,'EdgeColor','none');
  412. plot(x,smooth(y(2,:),smw),'k');
  413. x=spk(1).ms_bin(2:end-1);
  414. y=[mPSTH_ms-sePSTH_ms; mPSTH_ms; mPSTH_ms+sePSTH_ms];
  415. px=[x,fliplr(x)];
  416. py=[y(1,:), fliplr(y(3,:))];
  417. patch(px,smooth(py,smw),1,'FaceColor','r','FaceAlpha',0.3,'EdgeColor','none');
  418. plot(x,smooth(y(2,:),smw),'r');
  419. plot([-100 100],[0 0],'k')
  420. plot([msw(1) msw(1)],[-100 100],'b--');
  421. plot([msw(2) msw(2)],[-100 100],'b--')
  422. set(gca,'xlim',[-0.05 0.350],'ylim',[-.1 1.1])
  423. title('No Ms vs. MS (SEM)');
  424. text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
  425. subplot(1,3,3);hold on;
  426. area(spk(1).noms_bin(2:end-1),smooth(mPSTH_ms-mPSTH_nms,smw), 'FaceColor','k')
  427. plot([msw(1) msw(1)],[-100 100],'b--');
  428. plot([msw(2) msw(2)],[-100 100],'b--')
  429. set(gca,'xlim',[-0.1 0.350],'ylim',[-0.2 0.3])
  430. title('Ms-NoMS');
  431. text(0.25,0.25,['N = ' num2str(N)],'fontsize',12);
  432. %% Statistics ===========================================================
  433. ModWin = [0.150 0.160; 0.160 0.250];
  434. t=spk(1).noms_bin(2:end-1);
  435. MS = psth_ms(sel,2:end-1);
  436. NMS = psth_nms(sel,2:end-1);
  437. ExcWin = t>=ModWin(1,1) & t<=ModWin(1,2);
  438. SupWin = t>=ModWin(2,1) & t<=ModWin(2,2);
  439. ExcEffect = [mean(NMS(:,ExcWin),2) mean(MS(:,ExcWin),2)];
  440. SupEffect = [mean(NMS(:,SupWin),2) mean(MS(:,SupWin),2)];
  441. % 2-tailed
  442. [H_exc_2t,p_exc_2t, ci_exc_2t, stats_exc_2t] = ...
  443. ttest(ExcEffect(:,1),ExcEffect(:,2),'tail','both');
  444. [H_sup_2t,p_sup_2t, ci_sup_2t, stats_sup_2t] = ...
  445. ttest(SupEffect(:,1),SupEffect(:,2),'tail','both');
  446. % 1-tailed >> test specifically excitation and suppression
  447. [H_exc_1t,p_exc_1t, ci_exc_1t, stats_exc_1t] = ...
  448. ttest(ExcEffect(:,1),ExcEffect(:,2),'tail','left');
  449. [H_sup_1t,p_sup_1t, ci_sup_1t, stats_sup_1t] = ...
  450. ttest(SupEffect(:,1),SupEffect(:,2),'tail','right');
  451. figure;
  452. subplot(1,2,1);hold on;
  453. for s=1:size(ExcEffect,1)
  454. plot(1:2,ExcEffect(s,:),'o-','Markersize',6);
  455. end
  456. errorbar(1:2,mean(ExcEffect),std(ExcEffect)./sqrt(size(ExcEffect,1)),...
  457. 'ko-','MarkerSize',10,'MarkerFaceColor','k','LineWidth',2)
  458. set(gca,'xtick',1:2,'xticklabel',{'No MS','MS'},'xlim',[.5 2.5]);
  459. title(['Excitatory Effect of Microstim (' num2str( 1000*(ModWin(1,1)-0.150) ) '-' ...
  460. num2str( 1000*(ModWin(1,2)-0.150)) ' ms)']);
  461. subplot(1,2,2);hold on;
  462. for s=1:size(SupEffect,1)
  463. plot(1:2,SupEffect(s,:),'o-','Markersize',6);
  464. end
  465. errorbar(1:2,mean(SupEffect),std(SupEffect)./sqrt(size(SupEffect,1)),...
  466. 'ko-','MarkerSize',10,'MarkerFaceColor','k','LineWidth',2)
  467. set(gca,'xtick',1:2,'xticklabel',{'No MS','MS'},'xlim',[.5 2.5]);
  468. title(['Suppressive Effect of Microstim (' num2str( 1000*(ModWin(2,1)-0.150) ) '-' ...
  469. num2str( 1000*(ModWin(2,2)-0.150)) ' ms)']);
  470. fprintf(['\nMicrostimulation induced excitation:\n' ...
  471. 't(' num2str(stats_exc_1t.df) ') = ' num2str(stats_exc_1t.tstat) ...
  472. ', p = ' num2str(p_exc_1t) '\n']);
  473. fprintf(['Microstimulation induced suppression:\n'...
  474. 't(' num2str(stats_sup_1t.df) ') = ' num2str(stats_sup_1t.tstat) ...
  475. ', p = ' num2str(p_sup_1t) '\n']);
  476. %% Example plot for FIGURE 2A-C =========================================
  477. Check_IndV1;