UserMetaScript.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. %% Provide overview of each detected oscillation in a specified channel
  2. clear all
  3. close all
  4. experiments = get_experiment_list;
  5. % experiments=experiments(1,randperm(length(experiments)));
  6. % experiments=fliplr(experiments);
  7. save_data=1;
  8. repeatCalc=0;
  9. %% subfunction 1 - getStimProperties
  10. getStimulationProperties(experiments,save_data,repeatCalc) % insert StimPeriods in Excel Experiment List
  11. correctStimulationProperties(experiments,save_data,repeatCalc)
  12. %% Calculate basic features for baseline and stimulation (spiketime, spikephase, LFPpower... )
  13. mainGetBaselineProperties(experiments,save_data,repeatCalc)
  14. mainGetStimulationBasicFeatures(experiments,save_data,repeatCalc)
  15. % TO-DO
  16. % getStimulationFiringChannels(experiments,1,0)
  17. %% Plotting and comparisons!
  18. % for multiple experiments
  19. % Baseline
  20. expType={'B1'};
  21. plotBaselinePowerArea(experiments,expType)
  22. plotBaselineOscProperties(experiments,expType)
  23. % plotBaselineCoherence(experiments,1)
  24. % plotBaselinePower(experiments,1)
  25. % plotBaselineOscProperties(experiments,1)
  26. % % MUA
  27. % plotBaselineMUAPhase(experiments,1,0)
  28. % SUA
  29. % Stimulation
  30. % plotStimulationPower(experiments)
  31. % plotRaster(experiment)
  32. expType={'B1'};
  33. plotStimulationMUAspikeProbabiliy(experiments,expType,1) % I AM WORKING
  34. stimulusTypes={'ramp'};
  35. plotStimulationMUAISI(experiments,expType,stimulusTypes) % I AM WORKING
  36. firingRateSummaryForSPSS=plotStimulationMUAFiringRate(experiments,expType,stimulusTypes); % I AM WORKING
  37. plotStimulationMUASpikePhase(experiments,expType,stimulusTypes) % I AM WORKING
  38. plotStimulationPowerRatio(experiments,expType,stimulusTypes) % I AM WORKING
  39. % SUA
  40. plotStimulationBaselineSUASpikePhase(experiments,1)
  41. plotStimulationSUASpikePhase(experiments,1,0)
  42. plotStimulationSUAFiringRate(experiments,1)
  43. PlotStimulationSUAISI(experiments,1)
  44. % for single experiment
  45. n_experiment=101;
  46. expType={'B1'};
  47. plotStimulationMUAspikeProbabiliy(experiments(n_experiment),expType,1);
  48. % [DataWindowProbability]=plotStimulationMUAspikeProbabiliy(experiment,expType,1);
  49. CSC=23;
  50. stimulusTypes={'ramp'};
  51. plotStimulationRasterPlot(experiments(n_experiment), stimulusTypes, CSC)
  52. % get responding animals/CSCs
  53. clear all
  54. experiments = get_experiment_list;
  55. expType={'B1'};
  56. countPositveAnimal=0;
  57. for nExp = 1:length(get_experiment_list)
  58. experiment=experiments(nExp);
  59. if ~isempty(experiment.name) && strcmp(expType{1},experiment.Exp_type) && strcmp(experiment.IUEconstruct,'CAG-ChR2ET/TC-2AtDimer2')
  60. [CSCcalc,~,~,~] = getStimulationRespondingCSCsRamp(experiment,1,0);
  61. if CSCcalc >1
  62. countPositveAnimal=countPositveAnimal+1;
  63. positiveAnimal(countPositveAnimal)=nExp;
  64. CSCs.(['exp' num2str(nExp)]) = CSCcalc;
  65. end
  66. end
  67. end
  68. %% REVISION 2 (2016-11)
  69. close all
  70. clear all
  71. experiments = get_experiment_list;
  72. save_data=0;
  73. repeatCalc=0;
  74. resultsdir='Q:\Personal\Sebastian\ProjectOptoPFC\Analysis\Project3_HP_PFCopto\figures\AllCSCdeepLayers\';
  75. for n_experiment=163%[101:115 117:132 140:150 152:165 167:172 174 176 177 179:181];
  76. expType={'B1'};
  77. stimulusType='square';
  78. Frequency=2;
  79. downsampling_factor=1;
  80. cutFrequencies=[500 5000];
  81. for CSC=17:32
  82. stimStructure.(strcat('CSC',num2str(CSC)))=getStimulusSignal(experiments(n_experiment),CSC, stimulusType, Frequency,downsampling_factor);
  83. end
  84. Window=stimStructure.CSC17.samplingrate*2.98:stimStructure.CSC17.samplingrate*3.08;
  85. h=figure(n_experiment);
  86. hold on
  87. plot(stimStructure.(strcat('CSC',num2str(CSC))).time(Window),stimStructure.(strcat('CSC',num2str(CSC))).signalD(1,Window)*50-16*100,'b')
  88. for CSC=17:32
  89. plot(stimStructure.(strcat('CSC',num2str(CSC))).time(Window),stimStructure.(strcat('CSC',num2str(CSC))).signal(:,Window)-CSC*100,'k')
  90. for sweep=1:30
  91. filteredSignal(sweep,:)=ZeroPhaseFilterZeroPadding(stimStructure.(strcat('CSC',num2str(CSC))).signal(sweep,:),stimStructure.(strcat('CSC',num2str(CSC))).samplingrate,cutFrequencies);
  92. end
  93. plot(stimStructure.(strcat('CSC',num2str(CSC))).time(Window),filteredSignal(:,Window)-CSC*100,'b')
  94. plot(stimStructure.(strcat('CSC',num2str(CSC))).time(Window),mean(stimStructure.(strcat('CSC',num2str(CSC))).signal(:,Window))-CSC*100,'r')
  95. plot(stimStructure.(strcat('CSC',num2str(CSC))).time(Window),mean(filteredSignal(:,Window))-CSC*100,'g')
  96. axis tight
  97. title(num2str(n_experiment))
  98. end
  99. savefig(h,strcat(resultsdir,'allCSC',num2str(n_experiment),'.fig'))
  100. close all
  101. end
  102. %% REVISION 2 (2016-11)
  103. close all
  104. clear all
  105. experiments = get_experiment_list;
  106. save_data=0;
  107. repeatCalc=0;
  108. resultsdir='Q:\Personal\Sebastian\ProjectOptoPFC\Analysis\Project3_HP_PFCopto\figures\SpikeDetectionTest\';
  109. n_experiment=163
  110. expType={'B1'};
  111. stimulusType='square';
  112. Frequency=2;
  113. downsampling_factor=1;
  114. cutFrequencies=[500 5000];
  115. for CSC=26%17:32%27:28%17:32
  116. stimStructure.(strcat('CSC',num2str(CSC)))=getStimulusSignal(experiments(n_experiment),CSC, stimulusType, Frequency,downsampling_factor);
  117. for sweep=1:30
  118. stimStructure.(strcat('CSC',num2str(CSC))).filteredSignal(sweep,:)=ZeroPhaseFilterZeroPadding(stimStructure.(strcat('CSC',num2str(CSC))).signal(sweep,:),stimStructure.(strcat('CSC',num2str(CSC))).samplingrate,cutFrequencies);
  119. end
  120. h=figure;
  121. hold on
  122. % Window=stimStructure.(strcat('CSC',num2str(CSC))).samplingrate*2.98:stimStructure.(strcat('CSC',num2str(CSC))).samplingrate*3.08;
  123. Window=1:size(stimStructure.(strcat('CSC',num2str(CSC))).time,2);
  124. plot(stimStructure.(strcat('CSC',num2str(CSC))).time(Window),stimStructure.(strcat('CSC',num2str(CSC))).signalD(1,Window)*50,'b')
  125. for sweep=1:30
  126. time=stimStructure.(strcat('CSC',num2str(CSC))).time;
  127. filteredSignal=stimStructure.(strcat('CSC',num2str(CSC))).filteredSignal(sweep,:);
  128. plot(time(Window),filteredSignal(Window)-sweep*100,'k')
  129. % amplitudeDown threshold spike detection
  130. thr = std(filteredSignal)*3.5;
  131. [peakLocAmplDown, ~] = peakfinderOpto(filteredSignal,(max(filteredSignal)-min(filteredSignal))/4 ,-thr,-1,0);
  132. plot([time(Window(1)) time(Window(end))],[-thr -thr]-sweep*100,'k')
  133. if ~isempty(peakLocAmplDown)
  134. plot(time(peakLocAmplDown),-sweep*100-10,'y*')
  135. end
  136. % amplitudeUP threshold spike detection
  137. thr = std(filteredSignal)*3.5;
  138. [peakLocAmplUp, ~] = peakfinderOpto(filteredSignal,(max(filteredSignal)-min(filteredSignal))/4 ,thr,1,0);
  139. plot([time(Window(1)) time(Window(end))],[thr thr]-sweep*100,'k')
  140. if ~isempty(peakLocAmplDown)
  141. plot(time(peakLocAmplUp),-sweep*100+10,'y*')
  142. end
  143. % slope threshold spike detection
  144. dv=[0 diff(filteredSignal)];
  145. plot(time(Window),dv(Window)-sweep*100-50,'g')
  146. thr = std(dv)*3.0;
  147. [peakLocSlope, ~] = peakfinderOpto(dv,(max(dv)-min(dv))/4 ,-thr,-1,1);
  148. plot([time(Window(1)) time(Window(end))],[-thr -thr]-sweep*100-50,'g')
  149. if ~isempty(peakLocSlope)
  150. plot(time(peakLocSlope),-sweep*100-50,'b*')
  151. end
  152. % combined slope + amplitude
  153. spikeWindow=round(stimStructure.(strcat('CSC',num2str(CSC))).samplingrate*0.001);
  154. peakLocCombined=[];
  155. for f1=1:length(peakLocAmplDown)
  156. if any(ismember(peakLocAmplDown(f1)-spikeWindow:peakLocAmplDown(f1),peakLocSlope))
  157. if any(ismember(peakLocAmplDown(f1)-spikeWindow:peakLocAmplDown(f1),peakLocAmplUp))
  158. peakLocCombined=[peakLocCombined peakLocAmplDown(f1)];
  159. end
  160. end
  161. end
  162. if ~isempty(peakLocCombined)
  163. plot(time(peakLocCombined),-sweep*100-25,'r*')
  164. end
  165. % figure
  166. % hold on
  167. % plotspikeWindow=round(stimStructure.(strcat('CSC',num2str(CSC))).samplingrate*0.005);
  168. % for f1=1:length(peakLocCombined)
  169. % plot((-plotspikeWindow:plotspikeWindow)/stimStructure.(strcat('CSC',num2str(CSC))).samplingrate,filteredSignal(peakLocCombined(f1)-plotspikeWindow:peakLocCombined(f1)+plotspikeWindow))
  170. % end
  171. % axis tight
  172. % % Nonlinear Energy Operator (NEO) for spike detection
  173. % vNEO=filteredSignal(2:end-1).*filteredSignal(2:end-1)-filteredSignal(3:end).*filteredSignal(1:end-2);
  174. % vNEO=[0 vNEO 0];
  175. % plot(time(Window),vNEO(Window)-sweep*100-50,'b')
  176. %
  177. % thrNEO = std(vNEO)*10;
  178. % [peakLocThresholdNEO, ~] = peakfinderOpto(vNEO,0 ,thrNEO,1);
  179. % plot([time(Window(1)) time(Window(end))],[thrNEO thrNEO]-sweep*100-50,'b')
  180. % if ~isempty(peakLocThresholdNEO)
  181. % plot(time(peakLocThresholdNEO),-sweep*100-50,'r*')
  182. % end
  183. end
  184. axis tight
  185. title(strcat(num2str(n_experiment),'CSC',num2str(CSC)))
  186. % savefig(h,strcat(resultsdir,'exp',num2str(n_experiment),'CSC',num2str(CSC),'.fig'))
  187. % close all
  188. end