J_generateFigure10_correlLPlatency.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. %% generate Figure 10 and Figure 10 supplement 1 - Correlation analysis
  2. %firing analysis post lever insertion and correl with response latency
  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.01;
  10. Dura=[-2 4]; Tm=Dura(1):BSIZE:Dura(2);
  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) 0];
  15. postwin=[0 .5];
  16. postwin2=[Dura(1):0.05:Dura(2)]; %bounds should match Dura
  17. Slopebounds=[-1.5:0.25:1.5];
  18. R2Bounds=[0:0.05:0.5];
  19. PvalBounds=[0:0.01:0.5];
  20. Struct=10;
  21. XI=1;
  22. RunRegress=1;
  23. SAVEFIG=1;
  24. %R=[];R.Ninfo={};
  25. NN=0;
  26. pre=[]; post=[];
  27. if ~exist('RAW'), load ('RAWextendedtraining.mat'); RAW=RAW; end
  28. if ~exist('Ev'), load('Rextendedtraining_light.mat'); end
  29. load('C');
  30. %path='C:\FRED\GALLO\Exps\2009-present GoNoGo\FINAL\PLX Files GoNoGo\GoNoGo NEX files\RESULTgn14.xls';
  31. %%
  32. if RunRegress
  33. % PREALLOCATING
  34. for i=1:length(RAW)
  35. EvInd=strmatch('LeverInsertion',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  36. Rind=strmatch('First_LP',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  37. if sum(EvInd)~=0 && sum(Rind)~=0
  38. DS(i)=length(RAW(i).Erast{EvInd});
  39. Neur(i)=length(RAW(i).Nrast);
  40. end
  41. end
  42. MaxTrials=max(DS); MaxNeur=sum(Neur); MaxWin=length(postwin);
  43. C.Lat=NaN(MaxNeur, MaxTrials); % (neurons, trials)
  44. C.pre=NaN(MaxNeur,MaxTrials); % (neurons, trials)
  45. C.post=NaN(MaxNeur,MaxTrials); % (neurons, trials)
  46. C.postwin=NaN(MaxNeur,MaxTrials,MaxWin); % (neurons, trials, windows)
  47. %
  48. for i=1:length(RAW) %loops through sessions
  49. EvInd=strmatch('LeverInsertion',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  50. Rind=strmatch('First_LP',RAW(i).Einfo(:,2),'exact'); %finds the index of the event
  51. if sum(EvInd)~=0 && sum(Rind)~=0
  52. Dcell=MakePSR04(RAW(i).Erast(Rind),RAW(i).Erast{EvInd},[-1 60],{2,'first'});
  53. D=cell2mat(Dcell); %inds=find(~isnan(D));
  54. D(isnan(D))=60; %trials with no response are set to 10.25 to allow to use them in the correlation
  55. for j= 1:size(RAW(i).Nrast,1) %Number of neurons within sessions
  56. NN=NN+1;
  57. C.Lat(NN,1:length(RAW(i).Erast{EvInd}))=D;
  58. [PSR2,N2]=MakePSR04(RAW(i).Nrast(j),RAW(i).Erast{EvInd},Dura,{2});% makes trial by trail rasters. PSR1 is a cell(neurons, trials)
  59. for m=1:size(RAW(i).Erast{Rind},1) %loops through trials
  60. Resplat=RAW(i).Eint{1,8}(m)-RAW(i).Eint{1,7}(m);
  61. C.pre(NN,m)=sum(PSR2{1,m}<prewin(2) & PSR2{1,m}>prewin(1))/(abs(prewin(2)-prewin(1))); %neurons, trials
  62. C.postLAT1(NN,m)=sum(PSR2{1,m}<postwin(2) & PSR2{1,m}>postwin(1))/(abs(postwin(2)-postwin(1)));
  63. end %m loop
  64. fprintf('Neuron ID # %d\n',NN);
  65. end %j loop
  66. end %if
  67. end %i loop
  68. %% Runs the regression analysis
  69. for NN=1:MaxNeur
  70. RegX=[C.Lat(NN,:)', ones(size(C.Lat,2),1)];
  71. [C.SLOPEpre,C.STATSpre]=corr(C.pre(NN,:)',C.Lat(NN,:)','rows','pairwise','type','Spearman');
  72. [C.SLOPEpostLAT1(NN,:),C.STATSpostLAT1(NN,:)]= corr(C.postLAT1(NN,:)',C.Lat(NN,:)','rows','pairwise','type','Spearman');
  73. [C.SLOPEpostpre(NN,:),C.STATSpostpre(NN,:)]= corr((C.post(NN,:)-C.pre(NN,:))',C.Lat(NN,:)','rows','pairwise','type','Spearman');
  74. fprintf('CORREL Neuron ID # %d\n',NN);
  75. end
  76. % Saving data in C structure and excel file
  77. save('C.mat', 'C');
  78. Cmat=[];
  79. % Cmat=cat(2,C.STATSpre, C.SLOPEpre, C.STATSpost, C.SLOPEpost);
  80. %xlswrite(path,Cmat,'Correl', 'F3');
  81. end
  82. %% --------------Plots distribution of correlation variables SINGLE WINDOW -------------
  83. % POST WINDOW
  84. XI=1; clear A;
  85. for i=1:2
  86. figure(1)
  87. sel1=Coord(:,4)==i*10;
  88. sel2= sel1 & C.STATSpostLAT1(:,1)<PStat;
  89. A(1,:)=cat(2, sum(sel1), sum(sel2));
  90. h=subplot(2,2,i);
  91. xmin=floor(min(C.SLOPEpostLAT1(sel1,1)));
  92. xmax=ceil(max(C.SLOPEpostLAT1(sel1,1)));
  93. step=0.05;
  94. xcenters=xmin:step:xmax;
  95. Nsel1=hist(C.SLOPEpostLAT1(sel1,1),xcenters);
  96. Nsel2=hist(C.SLOPEpostLAT1(sel2,1),xcenters);
  97. hold on;
  98. bar(xcenters, Nsel1, 'w', 'EdgeColor', 'k', 'BarWidth', 1);alpha(0.3);
  99. bar(xcenters, Nsel2, 'k', 'EdgeColor', 'k', 'BarWidth', 1);
  100. plot([0 0], [0 30],'LineStyle',':','Color','k');
  101. %axis([-10 10 0 20]) %note: their is an outlier @-14 for shell
  102. pval1=signrank(C.SLOPEpostLAT1(sel1,1));
  103. pval2=signrank(C.SLOPEpostLAT1(sel2,1));
  104. MEANsel1=mean(C.SLOPEpostLAT1(sel2,1));
  105. plot([MEANsel1 MEANsel1], [0 10],'Color','r');
  106. %text(-5.8,9.8,sprintf('p=%d', pval1), 'Parent',h);
  107. %text(-5.8,8.8,sprintf('p=%d', pval2), 'Parent',h);
  108. subplot(2,2,i+2)
  109. [N,xcenters2]=hist(C.STATSpostLAT1(sel2,1),20);
  110. bar(xcenters2, N, 'k', 'EdgeColor', 'k', 'BarWidth', 1); alpha(0.3);
  111. axis ([0 ceil(max(xcenters2)*10)/10 0 ceil(max(N))+1]);
  112. end
  113. save('C.mat', 'C');