I_generateFigure7_correlRRvsFR.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. %% generate Figure 7 and S8 - Correlation analysis - RR vs FR
  2. %firing analysis during LP and correl with response rate
  3. %Analysis on all neurons without DLS/DMS dissociation
  4. %histogram for correlated neurons in each regions, in each class
  5. clear all;clc;
  6. tic
  7. global Dura Baseline Tm Tbase BSIZE Tbin
  8. SAVE_FLAG=1;
  9. BSIZE=0.05;
  10. Dura=[-25 60]; Tm=-1:BSIZE:60;
  11. Baseline=[-2 0]; Tbase=Baseline(1):BSIZE:Baseline(2); %used to calculate Z-scores
  12. Tbin=-1:0.005:1; %window used to determine the optimal binsize
  13. PStat=0.05;
  14. prewin=[Dura(1) -20];
  15. postwin=[0 .5];
  16. EventWin=[-0.5 0.5];
  17. postwin2=[Dura(1):0.05:Dura(2)]; %bounds should match Dura
  18. Slopebounds=[-1.5:0.25:1.5];
  19. R2Bounds=[0:0.05:0.5];
  20. PvalBounds=[0:0.01:0.5];
  21. Struct=[10 20];
  22. XI=1;
  23. RunRegress=0;
  24. SAVEFIG=1;
  25. %R=[];R.Ninfo={};
  26. NN=0;
  27. pre=[]; post=[];
  28. if ~exist('RAW'), load ('RAWextendedtraining.mat'); RAW=RAW; end
  29. if ~exist('Ev'), load('Rextendedtraining_light.mat'); end
  30. load('C.mat');
  31. %Smoothing
  32. Smoothing=1; %0 for raw and 1 for smoothing
  33. SmoothTYPE='lowess';
  34. SmoothSPAN=5;
  35. if Smoothing~=1, SmoothTYPE='NoSmoothing';SmoothSPAN=NaN; end
  36. %path='C:\FRED\GALLO\Exps\2009-present GoNoGo\FINAL\PLX Files GoNoGo\GoNoGo NEX files\RESULTgn14.xls';
  37. %%
  38. if RunRegress
  39. % PREALLOCATING
  40. for i=1:length(RAW)
  41. EvInd=strmatch('First_LP',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  42. Rind=strmatch('ReliableLP_DT',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  43. if sum(EvInd)~=0 && sum(Rind)~=0
  44. DS(i)=length(RAW(i).Erast{EvInd});
  45. Neur(i)=length(RAW(i).Nrast);
  46. end
  47. end
  48. MaxTrials=max(DS); MaxNeur=sum(Neur); MaxWin=length(postwin);
  49. % C.Lat=NaN(MaxNeur, MaxTrials); % (neurons, trials)
  50. C.preRR=NaN(MaxNeur,MaxTrials); % (neurons, trials)
  51. C.SEQ=NaN(MaxNeur,MaxTrials); % (neurons, trials)
  52. C.postwinRR=NaN(MaxNeur,MaxTrials,MaxWin); % (neurons, trials, windows)
  53. %
  54. for i=1:length(RAW) %loops through sessions
  55. EvInd=strmatch('First_LP',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  56. Rind=strmatch('ReliableLP_DT',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  57. if sum(EvInd)~=0 && sum(Rind)~=0
  58. Dcell2=MakePSR05(RAW(i).Erast(Rind),RAW(i).Erast{EvInd},[-1 60],{2}); % makes trial by trail
  59. for j= 1:size(RAW(i).Nrast,1) %Number of neurons within sessions
  60. NN=NN+1;
  61. [PSRNeur,Nneur]=MakePSR04(RAW(i).Nrast(j),RAW(i).Erast{EvInd},[-1 60],{1});% collapsed raster
  62. [PSR2,N2]=MakePSR04(RAW(i).Nrast(j),RAW(i).Erast{EvInd},Dura,{2});% makes trial by trail rasters. PSR1 is a cell(neurons, trials)
  63. [PTHneur,BW1,~]=MakePTH07(PSRNeur,repmat(N2, size(RAW(i).Nrast{j},1),1),{2,0,BSIZE});
  64. PTHneur=smooth(PTHneur,SmoothSPAN,SmoothTYPE)';
  65. C.PSTHraw(NN,1:length(Tm))=PTHneur;
  66. Search=find(Tm>=EventWin(1) & Tm<=EventWin(2));
  67. [C.MaxVal(NN,1),MaxInd]=max(C.PSTHraw(NN,Search));
  68. C.MaxTime(NN,1)=Tm(Search(1)+MaxInd-1);
  69. for m=1:size(RAW(i).Erast{EvInd},1) %loops through trials
  70. SequenceDur=RAW(i).Eint{1,6}(m)-RAW(i).Eint{1,5}(m);
  71. C.RR(NN,m)=length(Dcell2{1,m})/SequenceDur;
  72. C.preRR(NN,m)=sum(PSR2{1,m}<prewin(2) & PSR2{1,m}>prewin(1))/(abs(prewin(2)-prewin(1))); %neurons, trials
  73. C.SEQ(NN,m)=sum(PSR2{1,m}<SequenceDur & PSR2{1,m}>0)/SequenceDur;
  74. end %m loop
  75. fprintf('Neuron ID # %d\n',NN);
  76. end %j loop
  77. end %if
  78. end %i loop
  79. %% Runs the regression analysis
  80. for NN=1:MaxNeur
  81. RegX=[C.RR(NN,:)', ones(size(C.RR,2),1)];
  82. [C.SLOPEpreRR,C.STATSpreRR]=corr(C.preRR(NN,:)',C.RR(NN,:)','rows','pairwise','type','Spearman');
  83. [C.SLOPEseq(NN,:),C.STATSseq(NN,:)]= corr(C.SEQ(NN,:)',C.RR(NN,:)','rows','pairwise','type','Spearman');
  84. [C.SLOPEseqpre(NN,:),C.STATSseqpre(NN,:)]= corr((C.SEQ(NN,:)-C.preRR(NN,:))',C.RR(NN,:)','rows','pairwise','type','Spearman');
  85. fprintf('CORREL Neuron ID # %d\n',NN);
  86. end
  87. C.SelectionRR(:,1)=Coord(:,4)==10 & C.STATSseq(:,1)<PStat;
  88. C.SelectionRR(:,2)=Coord(:,4)==20 & C.STATSseq(:,1)<PStat;
  89. % Saving data in C structure and excel file
  90. save('C.mat', 'C');
  91. end
  92. %% --------------Plots distribution of correlation variables SINGLE WINDOW -------------
  93. % POST WINDOW
  94. figure;
  95. Struct=[10 20];
  96. clear A;
  97. for i=1:2 % loop through structure
  98. clear sel1;clear sel2;
  99. sel1=Coord(:,4)==i*10; %(R.Class(:,1)==-4); %& R.DSNSStat<PStat & (R.Ev(1).Meanz>R.Ev(2).Meanz);
  100. sel2= sel1 & C.STATSseq(:,1)<PStat;
  101. A(i,:)=cat(2, sum(Coord(:,4)==i*10), sum(sel1), sum(sel2));
  102. h=subplot(2,2,i);
  103. xmin=floor(min(C.SLOPEseq(sel1,1)));
  104. xmax=ceil(max(C.SLOPEseq(sel1,1)));
  105. step=0.05;
  106. xcenters=xmin:step:xmax;
  107. Nsel1=hist(C.SLOPEseq(sel1,1),xcenters);
  108. Nsel2=hist(C.SLOPEseq(sel2,1),xcenters);
  109. hold on;
  110. bar(xcenters, Nsel1, 'w', 'EdgeColor', 'k', 'BarWidth', 1);alpha(0.3);
  111. bar(xcenters, Nsel2, 'k', 'EdgeColor', 'k', 'BarWidth', 1);
  112. plot([0 0], [0 30],'LineStyle',':','Color','k');
  113. pval1=signrank(C.SLOPEseq(sel1,1));
  114. pval2=signrank(C.SLOPEseq(sel2,1));
  115. MEANsel1=mean(C.SLOPEseq(sel2,1));
  116. plot([MEANsel1 MEANsel1], [0 10],'Color','r');
  117. subplot(2,2,i+2)
  118. [N,xcenters2]=hist(C.STATSseq(sel2,1),20);
  119. bar(xcenters2, N, 'k', 'EdgeColor', 'k', 'BarWidth', 1); alpha(0.3);
  120. axis ([0 ceil(max(xcenters2)*10)/10 0 ceil(max(N))+1]);
  121. end
  122. A(:,4)=A(:,3)./A(:,2)*100;
  123. save('C.mat', 'C');