123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- function figure_binmod(fld)
- fprintf('\n======================================================\n');
- fprintf('-- Creating Figure binmod --\n');
- fprintf('======================================================\n');
- loaddir = fullfile(fld.basedir,'results','figure_neurotrace');
- savedir = fullfile(fld.basedir,'results','figure_binmod');
- mkdir(savedir);
- %% settings
- green = [23, 105, 13]./255;
- red = [201, 0, 34]./255;
- cols = [green; 0.3 0.3 0.3; red; 1.00,0.84,0.00];
- snrthres = 2.5; mindays = 3;
- do_cleantraces = true; % if true we throw out artefact traces
- bin.sz = 10; % ms
- bin.minmax = [0 250];
- %% plots
- % load traces
- monkeys = {'M1','M2'};
- %% plot
- f1 = figure;
- set(f1,'Position',[500 500 1600 800]);
- bonfcorr = true;
- if do_cleantraces
- load(fullfile(loaddir,'Traces_SNR_trialbased.mat'),...
- 's_traces_ALL','recsites','rsinc');
- end
- % individual animals
- for mi = 1:2
- monkey = monkeys{mi};
- load(fullfile(loaddir, [monkey '_averages_snr' num2str(snrthres) ...
- '_mindays' num2str(mindays) '.mat']),...
- 'traces','tracesLUT','env_t');
- % bin these traces
- bb_l = bin.minmax(1):bin.sz:bin.minmax(2);
- bb_r = bb_l+bin.sz;
- bb_c = (bb_l+bb_r)/2;
-
- if do_cleantraces
- tmp_traces=[]; tmp_LUT=[];
- for cond=1:3
- tmp_traces = [tmp_traces ; ...
- s_traces_ALL{mi,cond}(rsinc{mi,cond},:)];
- tmp_LUT = [tmp_LUT ; ...
- recsites{mi,cond}(rsinc{mi,cond}) ...
- cond.*ones(sum(rsinc{mi,cond}),1)];
- end
- traces_ = traces; tracesLUT_ = tracesLUT;
- traces = tmp_traces; tracesLUT = tmp_LUT;
- end
- traces_bin = nan(size(traces,1),length(bb_c));
- for sidx = 1:size(traces,1)
- for bidx = 1:length(bb_l)
- bbool = (env_t.*1e3)>=bb_l(bidx) & (env_t.*1e3)<bb_r(bidx);
- traces_bin(sidx,bidx) = mean(traces(sidx,bbool));
- end
- end
- traces_ALL{mi} = traces_bin;
- tracesLUT_ALL{mi} = tracesLUT;
- env_t_ALL{mi} = bb_c;
-
- figure(f1)
- mns = []; sems = []; trcs = cell(0);
-
- subplot(2,3,mi+1); hold on;
- for cond = 1:3
- incl = tracesLUT(:,2)==cond;
- incl_ALL{mi,cond} = incl;
-
- % calculate the mean across channels
- get_traces = traces_bin(incl,:);
- s_traces = get_traces;
- s_traces_ALL{mi,cond} = s_traces;
- trcs{cond} = s_traces; % for calculating the modulation onset
- end
- df = trcs{1} - trcs{2}; % difference for each channel separately
- mn = mean(df);
- csem = std(trcs{1} - trcs{2})./sqrt(size(trcs{1},1));
-
- % stats (wrong but something)
- p=nan(1,size(df,2));
- for bidx = 1:size(df,2)
- [h,p(bidx)] = ttest(df(:,bidx));
- end
- if bonfcorr; bonf = size(df,2); else; bonf = 1; end
- bar(bb_c,mn,'FaceColor',cols(1,:),'BarWidth',1);
- bar(bb_c(p>0.05/bonf),mn(p>0.05/bonf),...
- 'FaceColor',[.5 .5 .5],'BarWidth',1);
- errorbar(bb_c,mn,csem,'LineStyle','none','Color','k');
- title([monkeys{mi} ' TARG']); xlabel('time(ms)'); ylabel('dMUA');
- set(gca,'ylim',[-0.04 0.14]);
- firstsig = find(p<0.05/bonf & mn>0,1,'first');
- fprintf(['M' num2str(mi) '-T: First sign. positive bin at ' ...
- num2str(bb_c(firstsig)) '\n'])
- subplot(2,3,mi+4); hold on;
- df = trcs{3} - trcs{2}; % difference for each channel separately
- mn = mean(df);
- csem = std(trcs{3} - trcs{2})./sqrt(size(trcs{3},1));
- % stats (wrong but something)
- p=nan(1,size(df,2));
- for bidx = 1:size(df,2)
- [h,p(bidx)] = ttest(df(:,bidx));
- end
- if bonfcorr; bonf = size(df,2); else; bonf = 1; end
- bar(bb_c,mn,'FaceColor',cols(3,:),'BarWidth',1);
- bar(bb_c(p>0.05/bonf),mn(p>0.05/bonf),...
- 'FaceColor',[.5 .5 .5],'BarWidth',1);
- errorbar(bb_c,mn,csem,'LineStyle','none','Color','k');
- title([monkeys{mi} ' SD']); xlabel('time(ms)'); ylabel('dMUA');
- set(gca,'ylim',[-0.12 0.05]);
- firstsig = find(p<0.05/bonf & mn>0,1,'first');
- fprintf(['M' num2str(mi) '-SD: First sign. positive bin at ' ...
- num2str(bb_c(firstsig)) '\n'])
- end
- % pooled animals
- for cond = 1:3
- incl = [incl_ALL{1,cond}; incl_ALL{2,cond}];
-
- % calculate the mean across channels
- traces = [traces_ALL{1}; traces_ALL{2}];
- get_traces = traces(incl,:);
- s_traces = get_traces;
- trcs{cond} = s_traces; % for calculating the modulation onset
- end
- inRF = {'target','','distractor'};
-
- subplot(2,3,1);hold on
- df = trcs{1} - trcs{2}; % difference for each channel separately
- mn = mean(df);
- csem = std(trcs{1} - trcs{2})./sqrt(size(trcs{1},1));
- % stats (wrong but something)
- p=nan(1,size(df,2));
- for bidx = 1:size(df,2)
- [h,p(bidx)] = ttest(df(:,bidx));
- end
- if bonfcorr; bonf = size(df,2); else; bonf = 1; end
- bar(bb_c,mn,'FaceColor',cols(1,:),'BarWidth',1);
- bar(bb_c(p>0.05/bonf),mn(p>0.05/bonf),...
- 'FaceColor',[.5 .5 .5],'BarWidth',1);
- errorbar(bb_c,mn,csem,'LineStyle','none','Color','k');
- title('BOTH monkeys TARG'); xlabel('time(ms)'); ylabel('dMUA');
- set(gca,'ylim',[-0.04 0.14]);
- firstsig = find(p<0.05/bonf & mn>0,1,'first');
- fprintf(['POOLED-T: First sign. positive bin at ' ...
- num2str(bb_c(firstsig)) '\n'])
- subplot(2,3,4);hold on
- df = trcs{3} - trcs{2}; % difference for each channel separately
- mn = mean(df);
- csem = std(trcs{3} - trcs{2})./sqrt(size(trcs{3},1));
- % stats (wrong but something)
- p=nan(1,size(df,2));
- for bidx = 1:size(df,2)
- [h,p(bidx)] = ttest(df(:,bidx));
- end
- if bonfcorr; bonf = size(df,2); else; bonf = 1; end
- bar(bb_c,mn,'FaceColor',cols(3,:),'BarWidth',1);
- bar(bb_c(p>0.05/bonf),mn(p>0.05/bonf),...
- 'FaceColor',[.5 .5 .5],'BarWidth',1);
- errorbar(bb_c,mn,csem,'LineStyle','none','Color','k');
- title('BOTH monkeys SD'); xlabel('time(ms)'); ylabel('dMUA');
- set(gca,'ylim',[-0.12 0.05]);
- text(gca,10,-0.1,'Colored bars: p<0.05, Bonf. corr.')
- firstsig = find(p<0.05/bonf & mn>0,1,'first');
- fprintf(['POOLED-SD: First sign. positive bin at ' ...
- num2str(bb_c(firstsig)) '\n'])
- %% save figure
- figure(f1)
- saveas(gcf,fullfile(savedir,'figure_binmod.svg'));
|