ComputeSelectivity.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. function [OutAx,x,sii,si_LR] = ComputeSelectivity(ev,ts,cnd,varargin)
  2. %UNTITLED2 Summary of this function goes here
  3. % Detailed explanation goes here
  4. iod = @utils.inputordefault;
  5. pre = iod('pre',0,varargin);
  6. post = iod('post',1,varargin);
  7. binsz = iod('binsz',0.01,varargin);
  8. krn = iod('krn',0.1,varargin);
  9. clr = iod('color','b',varargin);
  10. corner=iod('corner',[0.1 0.1],varargin);
  11. ax_width=iod('ax_width',0.55,varargin);
  12. one_height=iod('one_height',0.248,varargin);
  13. total_height=iod('total_height',0.8,varargin);
  14. xlabel_str=iod('xlabel_str','Time from Subgoal / s',varargin);
  15. title_str = iod('title_str','Subgoal Only',varargin);
  16. if iscell(cnd)
  17. %cnd_nan = cellfun(@(x)isnan(x), cnd);
  18. cnd_nan = cellfun(@(x)strcmp(x,'null'), cnd);
  19. %cnd(cnd_nan) = 'NaN';
  20. cnd = categorical(cnd);
  21. n_cnd = categories(cnd);
  22. else
  23. cnd = categorical(cnd);
  24. n_cnd = categories(cnd);
  25. end
  26. if isscalar(krn)
  27. dx=ceil(5*krn);
  28. kx=-dx:binsz:dx;
  29. krn=normpdf(kx,0, krn);
  30. if isempty(find(kx==0, 1))
  31. error('Your binsz needs to divide 1 second into interger # of bins');
  32. end
  33. krn(kx<0)=0;
  34. krn=krn/sum(krn);
  35. end
  36. [Y,x]=stats.spike_filter(ev,ts,krn,'pre',pre,'post',post,'kernel_bin_size',binsz);
  37. for ci=1:numel(n_cnd)
  38. sampz=sum(cnd==n_cnd(1));
  39. ref=cnd==n_cnd(ci);
  40. y=Y(ref,:);
  41. ymn(ci,:) = nanmean(y,1);
  42. yst(ci,:)= stats.nanstderr(y,1);
  43. end
  44. dump = sort(ymn);
  45. %sii = (dump(end,:)-(mean(dump(1:end-1,:))/(size(ymn,1)-1)))./mean(ymn);
  46. sii = (dump(end,:)-(mean(dump(1:end-1,:))))./sum(ymn);
  47. dump = zeros(2,length(x));
  48. dump(1,:) = mean(ymn(1:2:end,:));%L
  49. dump(2,:) = mean(ymn(2:2:end,:));%R
  50. dump = sort(dump);
  51. si_LR = (dump(2,:)-dump(1,:))./sum(dump);
  52. ax_si_LR = draw.jaxes([corner,ax_width,one_height]);
  53. plot(ax_si_LR,x,si_LR,'LineWidth',3);
  54. line([0,0],[0,max(si_LR)+0.5])
  55. set(gca,'YLim',[0 max(si_LR)+0.5])
  56. set(gca,'XLim',[-pre post]);
  57. title([title_str,'Preferred L/R Selectivity'])
  58. xlabel(xlabel_str)
  59. ylabel('SI / a.u.')
  60. ax_sii = draw.jaxes([corner(1),corner(2)+total_height-one_height,ax_width,one_height]);
  61. plot(ax_sii,x,sii,'LineWidth',3);
  62. line([0,0],[0,max(sii)+0.5])
  63. set(gca,'YLim',[0 max(sii)+0.5])
  64. set(gca,'XLim',[-pre post]);
  65. title([title_str,'Preferred Direction Selectivity'])
  66. xlabel(xlabel_str)
  67. ylabel('SI / a.u.')
  68. OutAx(1) = ax_si_LR;
  69. OutAx(2) = ax_sii;
  70. end