%%Tuning %%Notes To plot Figure 1 Tuning % step 1. put a debugging red dot at line 161 in DataPlot.SUP_BasicTuning; this is % the line that begins pnl(1,2).select(); %step 2. open testdPrimeTouch.m and run lines 3,4,7,8,9,11; %step 3. next run the lines that follow this: plt.fig('units','inches','width',12,'height',5,'font','Arial','fontsize',9); % Basic Percent of units responsive to a given action pnl = panel(); pnl.margin=15; pnl.pack(2,3); pnl.fontsize=11; pnl.fontname='Arial'; pnl(1,1).select(); NC=13; ActionTuned=ActionPvals R', 'fontweight', 'bold','fontsize',6); [b,a]=signtest(specWithin); title(sprintf('Median = %.2f \n p = %2.1g',median(specWithin),b),'fontweight', 'bold','fontsize',6); set(gca, 'fontweight', 'bold','fontsize',6); % [a,b]=ttest(specWithin); % title(sprintf('mean = %.2f, p = %.2f',mean(specWithin),b)); A = R2Within(isValid,L); B = R2Across{L}(isValid,2); specAcross{L} = (abs(A) - abs(B))./(abs(A)+abs(B)); pnl(2,2).select(); histogram(specAcross{L},-1:.1:1); axis image square; axis tight; ylim([0 45]); % histogram(specAcross{L},-1:.1:1,'Normalization','pdf'); xlabel('R <-> L', 'fontweight', 'bold','fontsize',6); [b,a]=signtest(specAcross{L}); title(sprintf('Median = %.2f \n p = %2.1g',median(specAcross{L}),b),'fontweight', 'bold','fontsize',6); set(gca, 'fontweight', 'bold','fontsize',6); % [a,b]=ttest(specAcross{L}); % title(sprintf('mean = %.2f, p = %.2f',mean(specAcross{L}),b)); A = R2Within(isValid,R); B = R2Across{R}(isValid,2); specAcross{R} = (abs(A) - abs(B))./(abs(A)+abs(B)); pnl(2,3).select(); histogram(specAcross{R},-1:.1:1); axis image square; axis tight; ylim([0 45]); % histogram(specAcross{R},-1:.1:1,'Normalization','pdf'); xlabel('L <-> R', 'fontweight', 'bold','fontsize',6); [b,a]=signtest(specAcross{R}); title(sprintf('Median = %.2f \n p = %2.2g',median(specAcross{R}),b),'fontweight', 'bold','fontsize',6); set(gca, 'fontweight', 'bold','fontsize',6); %% Figure 4 Tuning plt.fig('units','inches','width',12,'height',5,'font','Arial','fontsize',9); % Basic Percent of units responsive to a given action pnl = panel(); pnl.margin=15; pnl.pack(2,3); pnl.fontsize=11; pnl.fontname='Arial'; pnl(1,1).select(); NC=13; Labels{10} = 'Null'; ActionTuned=ActionPvals .7 & PlotData{1}.UnitQuality<=2); % top 25 validUnits = find(PlotData{1}.UnitQuality==QualThresh); [r2sorted,r2sorti] = sort(PlotData{1}.R2(validUnits),'descend'); validUnits = validUnits(r2sorti(1:8)); [nx]=plt.getSubPlotDimensions(length(validUnits)); nx = [2 4]; plt.fig('units','inches','width',9,'height',5,'font','Arial','fontsize',9); pnl = panel(); pnl.margin=15; id=1; for unit=validUnits; plt.subaxis(nx(1),nx(2),id); gca; hold on; plt.shadedErrorBar(1:9,Coef(unit,1:9),CoefCI(unit,1:9)); id=id+1; axis tight; axis square; set(gca, 'fontweight', 'bold'); % title(sprintf('R2=%.2f',PlotData{1}.R2(unit))); ylabel('Firing Rate (Hz)', 'fontweight', 'bold', 'fontsize', 8); xlabel('Stimulation Site', 'fontweight', 'bold', 'fontsize', 8); end suptitle(sprintf('Best quality (%d)',QualThresh)); %% Figure 5 Distribution of Correlations figH = plt.fig('units','inches','width',10,'height',4,'font','Arial','fontsize',9); pnl = panel(); pnl.margin=15; pnl.pack(2,3); pnl.fontsize=11; pnl.fontname='Arial'; edges = 0:.01:.4; edges2 = -.02:.005:.09; diffLabel = {'Touch x Loom Near', 'Touch x Loom Far', 'Loom Near x Loom Far'}; % Plot true distributions of correlations pnl(1,1).select(); gca; hold on; ax1=gca; histogram(RelCorrs(:,1),edges, 'FaceColor',[0.3 0.3 0.7],'FaceAlpha',0.4); hold on; histogram(RelCorrs(:,2),edges,'FaceColor',[0.1 0.4 0.1880],'FaceAlpha',0.4); % histogram(RelCorrs(:,3),edges,'FaceColor',[0.45 0.45 0.25],'FaceAlpha',0.4); title('Distribution of Correlations','fontweight', 'bold', 'fontsize', 6); Leg = legend(diffLabel{1},diffLabel{2}); if i==1 set(legend,'Position',[0.5446 0.3774 0.0729 0.0339]); elseif i==2 set(legend,'Position',[0.5446 0.8019 0.0729 0.0339]); end legend boxoff; xlabel('Correlation','fontweight', 'bold', 'fontsize', 6); axis tight; set(gca,'fontweight', 'bold', 'fontsize', 6); ax1.FontWeight = 'bold'; xlim([0 0.35]) ylim([0 50]) %% Figure 4 Receptive Field Size % Run the file in the Desktop called RFSizeModified. Note, if the middle % section doesn't run (if it errors out) at first, comment out the title % line (with the sprintf). run the third section, and then come back to the % middle section (and remember to uncomment the sprintf line in the title). % this is needed because the fwhm (full width half max) isn't calculated % until the last section %% Figure 6 Tuning Curves plt.fig('units','inches','width',12,'height',5,'font','Arial','fontsize',9); % Basic Percent of units responsive to a given action pnl = panel(); pnl.margin=15; pnl.pack(2,3); pnl.fontsize=11; pnl.fontname='Arial'; pnl(1,1).select(); NC=13; ActionTuned=ActionPvals %s',leftCond,rightCond),'fontweight', 'bold','fontsize',11); ylim([0 1.1]); axis tight; axis square; set(gca,'fontweight', 'bold', 'fontsize', 6); ax1.FontWeight = 'bold'; tmpInd=tmpInd+1; end end %% Figure 3 Latency Main % very important note. for this figure, make sure that around lines 29 or % 30, use the version that says ResultsDir = % fullfile(env.get('results'),'FaceScratch','SUAnal',[Tag % '-Go'],'PopData'); and not % ResultsDir = fullfile(env.get('results'),'FaceScratch','SUAnal',[Tag '-Go'],'PopDataNewMod'); % To plot this figure go to the ImageryLatencyLR(varargin) section of % Analyze.FaceScratch2.m. Run the first portion with Dates, etc. Then load % alltrialdata. then, run the latency portion, , then debug marker at 499 % where it starts plt.fig. then run the following plt.fig('units','inches','width',9,'height',3,'font','Arial','fontsize',9); pnl = panel(); pnl.margin = 20; pnl.pack('h',{2/3 1/3}); pnl.fontsize=11; pnl.fontname='Arial'; pnl(1).select(); ax1 = gca; hold on; % Analyze.plotEventRelatedAverage(perfCVLRBoot,'nan','TimeVec',(tWs(:,1)+.025)); for i=1:2 for j=1:8 % A{i}(j,:)=smooth(perfCVLRDay{i}(j,:),10); A{i}(j,:)=perfCVLRDay{i}(j,:); end end Analyze.plotEventRelatedAverage(A,{'L','R'},'TimeVec',(tWs(:,1)+.025)); tmpLeg = legend('Left','Right','Location','southeast'); legend boxoff; set(tmpLeg,'FontWeight','bold'); % decodeLatMuLR = mean(decodeLatLR); clrs = lines(2); % tmp1 = plt.vline(decodeLatLRBoot(1),{'--','Color',clrs(1,:)}); % tmp2 = plt.vline(decodeLatLRBoot(2),{'--','Color',clrs(2,:)}); plt.vline(decodeLatLRBoot(1),{'--','Color',clrs(1,:)},sprintf(' %.2f ms',decodeLatLRBoot(1)*1000),[0 1.08],{'HorizontalAlignment','Left'}); plt.vline(decodeLatLRBoot(2),{'--','Color',clrs(2,:)},sprintf('%.2f ms ',decodeLatLRBoot(2)*1000),[0 1.08],{'HorizontalAlignment','Right'}); plt.vline(0,'k'); xlabel('Time relative to Touch Onset (s)', 'fontweight', 'bold', 'fontsize', 6); ylabel('Decode performance', 'fontweight', 'bold', 'fontsize', 6); title('Decode Performance Aligned by Touch Onset', 'fontweight', 'bold'); tmpTitleGCA = get(gca,'title'); tmpTitleGCA.Position(1) = tmpTitleGCA.Position(1)+0.25; tmpTitleGCA.Position(2) = tmpTitleGCA.Position(2)+0.03; xlim([-0.5 2.0]) set(gca,'fontweight', 'bold', 'fontsize', 6); ax1.FontWeight = 'bold'; hold on; tmpP = patch([-0.1 0.3 0.3 -0.1],[0.2 0.2 0.98 0.98],'r','HandleVisibility','off'); set(tmpP,'FaceColor',[0.3 0.3 0.3],'FaceAlpha',0.15); %% Figure 3 Latency Inset % very important note. for this figure, make sure that around lines 29 or % 30, use the version that says % ResultsDir = fullfile(env.get('results'),'FaceScratch','SUAnal',[Tag '-Go'],'PopDataNewMod'); % To plot this figure go to the ImageryLatencyLR(varargin) section of % Analyze.FaceScratch2.m. Run the first portion with Dates, etc. Then load % alltrialdata. then, run the latency portion, then debug marker at 499 % where it starts plt.fig. then run the following plt.fig('units','inches','width',9,'height',3,'font','Arial','fontsize',9); pnl = panel(); pnl.margin = 20; pnl.pack('h',{2/3 1/3}); pnl.fontsize=11; pnl.fontname='Arial'; pnl(2).select(); ax1 = gca; hold on; for i=1:2 for j=1:8 % A{i}(j,:)=smooth(perfCVLRDay{i}(j,:),10); A{i}(j,:)=perfCVLRDay{i}(j,:); end end Analyze.plotEventRelatedAverage(A,{'L','R'},'TimeVec',(tWs(:,1)+.025)); hold on; plot([0.05; 0.15], [0.35; 0.35], '-k', 'LineWidth', 2,'color',[0.4 .4 .4]); text(.1,0.30, '100 ms', 'HorizontalAlignment','center') % Analyze.plotEventRelatedAverage(perfCVLRBoot,'nan','TimeVec',(tWs(:,1)+.025)); % decodeLatMuLR = mean(decodeLatLR); clrs = lines(2); % plt.vline(decodeLatLRBoot(1),{'--','Color',clrs(1,:)},sprintf(' %.2f ms',decodeLatLRBoot(1)*1000),[0 1.1],{'HorizontalAlignment','Left'}); % plt.vline(decodeLatLRBoot(2),{'--','Color',clrs(2,:)},sprintf('%.2f ms ',decodeLatLRBoot(2)*1000),[0 1.1],{'HorizontalAlignment','Right'}); % plt.vline(decodeLatMeanFirst,'r--',sprintf('%.2f ms',decodeLatMeanFirst*1000)); set(gca,'XTick',[]) % plt.vline(0,'k'); xlabel('Time', 'fontweight', 'bold', 'fontsize', 6); ylabel('Decode performance', 'fontweight', 'bold', 'fontsize', 6); title('Shaded Region Expanded', 'fontweight', 'bold'); xlim([-0.25 0.20]) set(gca,'fontweight', 'bold', 'fontsize', 6); ax1.FontWeight = 'bold'; %% Figure 3 Latencies % very important note. for this figure, make sure that around lines 29 or % 30, use the version that says ResultsDir = % fullfile(env.get('results'),'FaceScratch','SUAnal',[Tag % '-Go'],'PopData'); and not % ResultsDir = fullfile(env.get('results'),'FaceScratch','SUAnal',[Tag '-Go'],'PopDataNewMod'); % To plot this figure go to the ImageryLatencyLR(varargin) section of % Analyze.FaceScratch2.m. Run the first portion with Dates, etc. Then load % alltrialdata. then, run the latency portion, , then debug marker at 499 % where it starts plt.fig. then run the following ttt = (-1.5:.005:1.5); NShuffs = 100; zzidx = find(ttt==0); % FR = Analyze.getNeuralData(AlignedTrialData,ASF,ttt); FR = Analyze.getNeuralData(AlignedTrialData,ASF,ttt,'smooth',10); Conds = Analyze.returnFieldValues(AlignedTrialData,'Condition'); if all(LabelIdx2Incl) UnitLatencyFileName = fullfile(ResultsDir,'AlignedData','UnitLatencyResults3'); else UnitLatencyFileName = fullfile(ResultsDir,'AlignedData','UnitLatencyNoHand'); end if anyRecalc || ~exist([UnitLatencyFileName '.mat'],'file') for i = 1:size(ASF,1) fprintf('Unit %d/%d...\n',i,size(ASF,1)); for c = 1:length(UConds) cIdx = strcmp(Conds,UConds{c}); sigg = nanmean(FR(cIdx,:,i)); [iptAll{i,c},res(i,c)] = findchangepts(sigg,'statistic','linear','MaxNumChanges',1); [iptMean{i,c},resMean(i,c)] = findchangepts(sigg,'statistic','mean','MaxNumChanges',1); for j=1:NShuffs sigg2=Shuffle(sigg); [~,resShuff(i,j,c)]=findchangepts(sigg2,'statistic','linear','MaxNumChanges',1); end prct(i,c)=nnz(resShuff(i,:,c) R2Cutoff(i)); InclIdx{i}(:,c) = ~emptyCell & (R2Meas{i}(:,c) > R2Cutoff(i)) & IsSigPrct(:,c); latTime{i}{c} = ttt([iptAll{InclIdx{i}(:,c),c}]); histogram(latTime{i}{c}+.025,-1.5:.05:1.5); hold on set(gca,'fontweight', 'bold', 'fontsize', 6); ax1.FontWeight = 'bold'; if ~isempty(latTime{i}{c}) ksdensity(latTime{i}{c}+.025,'bandwidth',.025); end switch UConds{c} case 'CheekL' tmpCond{c} = 'Left Cheek'; case 'CheekR' tmpCond{c} = 'Right Cheek'; case 'HandL' tmpCond{c} = 'Left Hand'; case 'HandR' tmpCond{c} = 'Right Hand'; case 'ShoulderL' tmpCond{c} = 'Left Shoulder'; case 'ShoulderR' tmpCond{c} = 'Right Shoulder'; end title(tmpCond{c},'fontweight', 'bold', 'fontsize',6); xlabel('Response Latency (s)','fontweight', 'bold', 'fontsize',6); ylabel('Number of Units (%)','fontweight', 'bold', 'fontsize',6); axis tight; xlim([-.25 1]); tmp=latTime{i}{c}+.025; tmp(tmp>1 | tmp <-.25)=[]; md=median(tmp); ylim([0 21]); plt.vline(md,{'k'}); if strcmp(UConds{c},'CheekL') || strcmp(UConds{c},'CheekR') ||strcmp(UConds{c},'ShoulderR') text(md+0.04,19.5,sprintf('Median = %0.1f ms',md*1000),'fontsize',6', 'fontweight','bold') else text(md+0.07,19.5,sprintf('Median = %0.1f ms',md*1000),'fontsize',6', 'fontweight','bold') end end suptitle(['Latencies: ' R2MeasLabel{i}]);