Browse Source

Spot data and code

Helene Schreyer 3 years ago
parent
commit
3db71b39a2

+ 30 - 0
Spot/code patterned spot/BC_mainPatternedSpot.asv

@@ -0,0 +1,30 @@
+%Guide for the patterned spot analysis
+%Check out the Documentation_Data.pdf, which contains relevant information
+%for analysing the patterned stimulus
+clear;
+close all;
+
+%% Do the patterned spot analysis
+loadData='Z:\Manuscript\BC_XY_LN\Puplishing\DataAvailable\Spot\'; %path of the BC files for patterned spot (has to be adapted to your own path)
+filename='18d130037Comp.mat'; %BC file to analyse: for example here we use file 16422006Comp from cell 1, recorded in retina 2 on 160422
+Hz=1; % given in the excel file LogInfo_PatternedSpot.xlsx for the corresponding file
+%the input frames you need, this part depends on whether you record with
+%stimulus version 1 or 2 get the start and end points of each patterned spot from LogInfo_PatternedSpot.xlsx.
+
+%% stimulus version 1
+start_halfSpot=51; end_halfSpot=57;
+start_quarterSpot=59; end_quarterSpot=65;
+start_25microSpot=75; end_25microSpot=81;
+inputFrames=[start_halfSpot,end_halfSpot,start_quarterSpot,end_quarterSpot,...
+    start_25microSpot,end_25microSpot];
+% %% stim version 2
+% start_halfSpot=234; end_halfSpot=240;
+% start_quarterSpot=243; end_quarterSpot=249;
+% start_25microSpot=252; end_25microSpot=258;
+% start_10microSpot=261; end_10microSpot=267;
+% start_UniformSpot=225; end_UniformSpot=231;
+% inputFrames=[start_halfSpot,end_halfSpot,start_quarterSpot,end_quarterSpot,...
+%     start_25microSpot,end_25microSpot,start_10microSpot,end_10microSpot,...
+%     start_UniformSpot,end_UniformSpot];
+
+[patternedSpot_output]=BC_patternedSpot(loadData,filename,Hz,inputFrames);%example code to analyse the patterned spot responses

+ 30 - 0
Spot/code patterned spot/BC_mainPatternedSpot.m

@@ -0,0 +1,30 @@
+%Guide for the patterned spot analysis
+%Check out the Documentation_Data.pdf, which contains relevant information
+%for analysing the patterned stimulus
+clear;
+close all;
+
+%% Do the patterned spot analysis
+loadData='Z:\Spot\'; %path of the BC files for patterned spot (has to be adapted to your own path)
+filename='16422006Comp.mat'; %BC file to analyse: for example here we use file 16422006Comp from cell 1, recorded in retina 2 on 160422
+Hz=1; % given in the excel file LogInfo_PatternedSpot.xlsx for the corresponding file
+%the input frames you need, this part depends on whether you record with
+%stimulus version 1 or 2 get the start and end points of each patterned spot from LogInfo_PatternedSpot.xlsx.
+
+%% stimulus version 1
+start_halfSpot=51; end_halfSpot=57;
+start_quarterSpot=59; end_quarterSpot=65;
+start_25microSpot=75; end_25microSpot=81;
+inputFrames=[start_halfSpot,end_halfSpot,start_quarterSpot,end_quarterSpot,...
+    start_25microSpot,end_25microSpot];
+% %% stim version 2
+% start_halfSpot=234; end_halfSpot=240;
+% start_quarterSpot=243; end_quarterSpot=249;
+% start_25microSpot=252; end_25microSpot=258;
+% start_10microSpot=261; end_10microSpot=267;
+% start_UniformSpot=225; end_UniformSpot=231;
+% inputFrames=[start_halfSpot,end_halfSpot,start_quarterSpot,end_quarterSpot,...
+%     start_25microSpot,end_25microSpot,start_10microSpot,end_10microSpot,...
+%     start_UniformSpot,end_UniformSpot];
+
+[patternedSpot_output]=BC_patternedSpot(loadData,filename,Hz,inputFrames);%example code to analyse the patterned spot responses

+ 140 - 0
Spot/code patterned spot/BC_patternedSpot.m

@@ -0,0 +1,140 @@
+function [patternedSpot_output]=BC_patternedSpot(loadData,filename,Hz,inputFrames)
+%[patternedSpot_output]=BC_patternedSpot(loadData,filename,Hz,inputFrames)
+%this function shows the analysis for the patterned spot stimulus. The
+%baseline average response per patterned spot stimulus is computed.
+%Inputs:
+%               loadData = the folder path of the patterned spot files
+%               filename = the filename of the BC of interest
+%               Hz = reversing frequency of the patterned spot
+%               inputFrames = the starting and ending frame times of the 
+%               patterned spots from the excel file LogInfo_PatternedSpot.xlsx   
+%
+%Outpus:        patternedSpot_output = structure containing the output
+%               average membrane potential per patterned spot and fourier output
+%
+% code by HS last modiefied March 2021
+
+%% Constants
+%starting and end frame for the split-spot
+start_halfSpot=inputFrames(1);
+end_halfSpot=inputFrames(2);
+%starting and end frame for the spot divided into 4 quarters
+start_quarterSpot=inputFrames(3);
+end_quarterSpot=inputFrames(4);
+%starting and end frame for the spot with 25micron subfields
+start_25microSpot=inputFrames(5);
+end_25microSpot=inputFrames(6);
+%start and end frame for the spots recorded with version 2 (see excel file)
+if length(inputFrames) > 6
+    %for 10 micron subfields
+    start_10microSpot=inputFrames(7); end_10microSpot=inputFrames(8);
+    %for the uniform spot
+    start_UniformSpot=inputFrames(9); end_UniformSpot=inputFrames(10);
+end
+
+%-------------------------------------------------------------------------------
+%% 1. load the patterned spot file
+data=load([loadData,filename]); %load the file
+
+%------------------------------------------------------------------------------------------
+%% 2. build average response to split spot
+indx=start_halfSpot; %you start with the splitspot
+basValue=200;%get baseline (200ms) before the stimulus.
+%The index in the excel file gives
+%the start of the 2 trial already, one trial is 1000ms, therefore you
+%have to go 1200ms before the index to get the 200ms beseline
+oneperiod=1000/Hz; %time in ms of one period of the stimulus
+
+%get the average baselined response to the split spot
+memPotAVG_splitSpot=getAVGResponse(data,basValue,oneperiod,indx);
+
+%------------------------------------------------------------------------------------------
+%% 3. build average response to quarter spot
+indx=start_quarterSpot; %you start with the spot
+%get the average baselined response to the quarter spot
+memPotAVG_quarterSpot=getAVGResponse(data,basValue,oneperiod,indx);
+
+%------------------------------------------------------------------------------------------
+%% 4. build average response to 25micron spot
+indx=start_25microSpot; %you start with the spot
+%get the average baselined response to the 25micron spot
+memPotAVG_25microSpot=getAVGResponse(data,basValue,oneperiod,indx);
+
+%------------------------------------------------------------------------------------------
+%% 5. only for stimulus version 2 build average for 10micron spot and uniform spot
+if length(inputFrames) > 6
+    %------------------------------------------------------------------------------------------
+    %% 5.1 build average response to 15micron spot
+    indx=start_10microSpot; %you start with the spot
+    %get the average baselined response to the 10micron spot
+    memPotAVG_10microSpot=getAVGResponse(data,basValue,oneperiod,indx);
+    
+    %------------------------------------------------------------------------------------------
+    %% 5.2 build average response to uniform spot
+    indx=start_UniformSpot; %you start with the spot
+    %get the average baselined response to the uniform spot
+    memPotAVG_uniformSpot=getAVGResponse(data,basValue,oneperiod,indx);
+    
+else
+    %get the response to the uniform spot from the loaded file
+    memPotAVG_uniformSpot=data.uniformTraceAVG;
+end
+
+%------------------------------------------------------------------------------------------
+%% 6. Plot the data
+figure;
+%uniform spot
+subplot(2,2,1)
+%get max and min to set same axis for all the patterned
+%spot
+YLIM=[min([memPotAVG_uniformSpot,memPotAVG_splitSpot,memPotAVG_quarterSpot,memPotAVG_25microSpot])-0.5,...
+    max([memPotAVG_uniformSpot,memPotAVG_splitSpot,memPotAVG_quarterSpot,memPotAVG_25microSpot])+0.5];
+plot(memPotAVG_uniformSpot,'k','linewidth',3) %original membrane potential
+title('uniform spot')
+xlabel('time(ms)')
+ylabel('voltage (mV)')
+ylim(YLIM);
+%split spot
+subplot(2,2,2)
+plot(memPotAVG_splitSpot,'k','linewidth',3) %original membrane potential
+title('split spot')
+xlabel('time(ms)')
+ylabel('voltage (mV)')
+ylim(YLIM);
+%1/4 spot
+subplot(2,2,3)
+plot(memPotAVG_quarterSpot,'k','linewidth',3) %original membrane potential
+title('quarter spot')
+xlabel('time(ms)')
+ylabel('voltage (mV)')
+ylim(YLIM);
+%25micron subfield spot
+subplot(2,2,4)
+plot(memPotAVG_25microSpot,'k','linewidth',3) %original membrane potential
+title('25micron subfields spot')
+xlabel('time(ms)')
+ylabel('voltage (mV)')
+ylim(YLIM);
+
+%-------------------------------------------------------------------------------
+%% 5. add variables into the output
+patternedSpot_output.memPotAVG_uniformSpot=memPotAVG_uniformSpot;
+patternedSpot_output.memPotAVG_splitSpot=memPotAVG_splitSpot;
+patternedSpot_output.memPotAVG_quarterSpot=memPotAVG_quarterSpot;
+patternedSpot_output.memPotAVG_25microSpot=memPotAVG_25microSpot;
+if length(inputFrames) > 6
+    patternedSpot_output.memPotAVG_10microSpot=memPotAVG_10microSpot;
+end
+end
+
+function membPotAVG_trBas=getAVGResponse(data,basValue,oneperiod,indx)
+memPot_basTemp=data.membPot(data.ttls_ms(indx)-oneperiod-basValue: ...
+    data.ttls_ms(indx)-oneperiod-1); %baseline 200ms before
+for jj=1:3 %amount of black spot start per size ->only analyse 3!
+    membPot_perTrial(jj,:)=data.membPot(data.ttls_ms(indx): ...
+        data.ttls_ms(indx)+oneperiod-1); %duration 1000 ms for black and white together
+    indx=indx+2;
+end
+memPotAVG= mean(membPot_perTrial);
+membPotAVG_trBas= memPotAVG-mean(memPot_basTemp);
+end

+ 43 - 0
Spot/code uniform spot/BC_mainUniformSpot.m

@@ -0,0 +1,43 @@
+%Guide for the uniform spot analysis
+%Check out the Documentation_Data.pdf, which contains relevant information
+%for analysing the uniform stimulus
+clear;
+close all;
+
+%% Set the general variable (the same for all spot versions)
+loadData='Z:\Spot\'; %path of the BC files for uniform spot (has to be adapted to your own path)
+spotDuration=500; % given in the excel file LogInfo_UniformSpot.xlsx 
+grayDuration=1000; % given in the excel file LogInfo_UniformSpot.xlsx for the corresponding file
+
+%% run spot analysis for stimulus version 1 and 2
+%path for the stimulus signal for verion 1 or 2 -> here the black and white
+%spots are recorded in different files
+filename='172030015Comp.mat'; %BC file to analyse (black spot): for example here we use file 172030015Comp from cell 1, recorded in retina 1 on 170203
+filename2='172030016Comp.mat'; %BC file to analyse (white spot): for example here we use file 172030016Comp from cell 1, recorded in retina 1 on 170203
+spotVersion=2;% uniform spot version given in excel file LogInfo_UniformSpot.xlsx
+%get the path for loading the stimulus signal: stimulusVersion1.mat or
+%stimulusVersion2.mat
+if spotVersion==1 
+    % Path for loading the stimulus version 1: stimulusVersion1.mat
+    pathStimSignal='Z:\Manuscript\BC_XY_LN\Puplishing\DataAvailable\Spot\stimulusVersion1.mat'; %has to be adapted to your own structure
+elseif spotVersion==2
+    % Path for loading the stimulus signal version 2: stimulusVersion2.mat
+    pathStimSignal='Z:\Manuscript\BC_XY_LN\Puplishing\DataAvailable\Spot\stimulusVersion2.mat';
+end
+[patternedSpot_output]=BC_uniformSpot(loadData,filename,filename2,spotDuration,...
+    grayDuration,spotVersion,pathStimSignal);%example code to analyze the responses to the uniform spots
+
+%% run spot analysis for stimulus version 3
+filename='18d130037Comp.mat'; %BC file to analyse, here you only have one file: 18d130037Comp for cell1 in retina 3 on 181213
+pathStimSignal='Z:\Manuscript\BC_XY_LN\Puplishing\DataAvailable\Spot\stimulusVersion3.mat'; %to get the path for loading the stimulus signal
+start_blackSpot=1; end_blackSpot=111;
+start_whiteSpot=112; end_whiteSpot=222;
+inputFrames=[start_blackSpot,end_blackSpot,start_whiteSpot,end_whiteSpot];
+[patternedSpot_output3]=BC_uniformSpot3(loadData,filename,spotDuration,grayDuration, ...
+    inputFrames,pathStimSignal);%example code to analyze the responses to uniform spots
+
+%% run spot analysis for stimulus version 4
+filename='15o160046Comp.mat'; %BC file to analyse, here you only have one file: 15o160046Comp for cell 3 in retina 2 on the 151016
+grayDuration=4000; % given in the excel file LogInfo_UniformSpot.xlsx for the corresponding file
+[patternedSpot_output4]=BC_uniformSpot4(loadData,filename,spotDuration,grayDuration);%example code to preprocess the reversing uniform spots
+

+ 187 - 0
Spot/code uniform spot/BC_uniformSpot.m

@@ -0,0 +1,187 @@
+function [uniformSpot_output]=BC_uniformSpot(loadData,filename,filename2,spotDuration,grayDuration,spotVersion,pathStimSignal)
+%[uniformSpot_output]=BC_uniformSpot(loadData,filename,filename2,spotDuration,grayDuration,spotVersion,pathStimSignal)
+%this function shows the example analysis for the uniform spot stimulus with
+%different spot sizes for both preferred and non-preferred contrasts. It is
+%used for cells that were recorded with stimulus version 1 and 2.
+%Inputs:
+%               loadData = the folder path of the patterned spot files
+%               filename = the filename of the BC of interest for black
+%               contrast
+%               filename2 = the filename of the BC of interest for white
+%               contrast
+%               spotDuration = duration of spot in ms, found in 
+%               the excel file LogInfo_UniformSpot.xlsx   
+%               grayDuration = duration of gray screen in ms, found in 
+%               the excel file LogInfo_UniformSpot.xlsx 
+%               spotVersion = spot version used, found in 
+%               the excel file LogInfo_UniformSpot.xlsx 
+%               pathStimSignal = folder path to load the sequence of spot
+%               sizes shown
+%
+%Outpus:        uniformSpot_output = structure containing the output
+%               average membrane potential per spot size of the uniform
+%               spot for the black and white spot
+%
+% code by HS last modiefied March 2021
+
+%% Constants
+mircoMeter_proPixel=2.5; %one monitor pixel is 2.5 micrometers
+
+%-------------------------------------------------------------------------------
+%% 1. load the spot sizes
+if spotVersion ==1
+    npatterns=13; %13 spot sizes were shown
+    micro_meter=[2,4,5,6,8,10,16,24,32,50,100,200,240]'*2*mircoMeter_proPixel; %spot diameter size in micro meters
+elseif spotVersion==2
+    npatterns=11; %11 spot sizes were shown
+    micro_meter=[2,4,6,8,10,16,24,32,50,100,200]'*2*mircoMeter_proPixel; %spot diameter size in micro meters
+end
+%for plotting add the mircometer label
+micrometer_label=repmat(' \mum',size(micro_meter,1),1);
+micro_meter_withLabel=strcat (num2str(micro_meter),micrometer_label);
+
+load(pathStimSignal); %load the order of the presentation of the diameter sizes. See Documentation_Data_BCRecordings. It contains values from 0-12 and the numbers refer to the spot size presented, where 0=smallest spot size and 12=largest spot size. It contains the pulses for a 15 minute recording
+
+%------------------------------------------------------------------------------------------
+%% 2. extract the membrane potential data for each spot size of the black spot and build the average
+data=load([loadData,filename]); %load the file for the black spot
+%only get the frames where the gray screen was shown (that you have one
+%frame per trial)
+ttls_ms_forCond=data.ttls_ms(1:2:end);
+%correct stimulus signal for the amount of ttls pulses you showed the
+%spot -> usually less than 15minutes
+stimulus_corr=stimulus(1:size(ttls_ms_forCond,1),:);
+
+%extract the membrane potential per spot
+membPot_perTrialBlackSpot=cell(1,npatterns);
+for j=0:npatterns-1 %loop over spot sizes
+    spot_cond=find(stimulus_corr==j);%get all the spots with same size
+    ttls_forCond=ttls_ms_forCond(spot_cond);%get the ttls signals for this circle size
+    if ~isempty(ttls_forCond)
+        %get the membrane potenial for this ttls signal (start gray screen) and go until
+        %the next spot (grayScreen 1000ms+500msSpot+1000gray)
+        for jj=1:length(ttls_forCond)
+            if length(data.membPot)>=(ttls_forCond(jj)+spotDuration-1+grayDuration*2)==1 %only if you have enought data, when you end the recording it can happen that you end it during a trial -> those trials you dont consider here
+                membPot_perTrialBlackSpot{j+1}(jj,:)=data.membPot(ttls_forCond(jj): ...
+                    (ttls_forCond(jj)+spotDuration-1+2*grayDuration)); %duration-1 -> because the next trial would start there
+            end
+        end
+    end
+    clear spot_cond ttls_forCond
+end
+
+
+% baseline on trial by trial bases -> substract from the time series of each trial
+% the mean value of the 200 ms before the spot arrives
+membPot_trBasMeanBlackSpot=cell(1,npatterns);
+basValue=-200;%amount of baseline ->200ms
+for ww=1:length(membPot_perTrialBlackSpot)%nbr of spot sizes
+    val_before=membPot_perTrialBlackSpot{ww}(:,grayDuration+basValue:grayDuration-1);
+    byTrBas_perSpot=(mean(val_before,2));
+    trBas_repMAt=repmat(byTrBas_perSpot,1, ...
+        size(membPot_perTrialBlackSpot{ww}(:,grayDuration+1:end),2)); %directly take the signal after gray screen
+    membPot_trBasMeanBlackSpot{ww}=mean(membPot_perTrialBlackSpot{ww}(:,grayDuration+1:end)- ...
+        trBas_repMAt,1);%mean for each trial, directly take the signal after gray screen
+    clear trBas_perSpotrepMAt
+end
+
+
+%------------------------------------------------------------------------------------------
+%% 3. extract the membrane potential data for each spot size of the white spot and build the average
+data=load([loadData,filename2]); %load the file for the white spot
+%only get the frames where the gray screen was shown (that you have one
+%frame per trial)
+ttls_ms_forCond=data.ttls_ms(1:2:end);
+%correct stimulus signal for the amount of ttls pulses you showed the
+%spot -> usually less than 15minutes
+stimulus_corr=stimulus(1:size(ttls_ms_forCond,1),:);
+clear stimulus
+
+%extract the membrane potential per spot
+membPot_perTrialWhiteSpot=cell(1,npatterns);
+for j=0:npatterns-1 %loop over spot sizes
+    spot_cond=find(stimulus_corr==j);%get all the spots with same size
+    ttls_forCond=ttls_ms_forCond(spot_cond);%get the ttls signals for this circle size
+    if ~isempty(ttls_forCond)
+        %get the membrane potenial for this ttls signal (start gray screen) and go until
+        %the next spot (grayScreen 1000ms+500msSpot+1000gray)
+        for jj=1:length(ttls_forCond)
+            if length(data.membPot)>=(ttls_forCond(jj)+spotDuration-1+grayDuration*2)==1 %only if you have enought data, when you end the recording it can happen that you end it during a trial -> those trials you dont consider here
+                membPot_perTrialWhiteSpot{j+1}(jj,:)=data.membPot(ttls_forCond(jj): ...
+                    (ttls_forCond(jj)+spotDuration-1+2*grayDuration)); %duration-1 -> because the next trial would start there
+            end
+        end
+    end
+    clear spot_cond ttls_forCond
+end
+
+
+% baseline on trial by trial bases -> substract from the time series of each trial
+% the mean value of the 200 ms before the spot arrives
+membPot_trBasMeanWhiteSpot=cell(1,npatterns);
+basValue=-200;%amount of baseline ->200ms
+for ww=1:length(membPot_perTrialWhiteSpot)%nbr of spot sizes
+    val_before=membPot_perTrialWhiteSpot{ww}(:,grayDuration+basValue:grayDuration-1);
+    byTrBas_perSpot=(mean(val_before,2));
+    trBas_repMAt=repmat(byTrBas_perSpot,1, ...
+        size(membPot_perTrialWhiteSpot{ww}(:,grayDuration+1:end),2)); %directly take the signal after gray screen
+    membPot_trBasMeanWhiteSpot{ww}=mean(membPot_perTrialWhiteSpot{ww}(:,grayDuration+1:end)- ...
+        trBas_repMAt,1);%mean for each trial, directly take the signal after gray screen
+    clear trBas_perSpotrepMAt
+end
+
+
+%------------------------------------------------------------------------------------------
+%% 4. Plot the data
+figure;
+subplot(1,2,1)
+%black spot with different sizes If you use earlier MATLAB versions you
+%might have to choose for each spot size a different color
+%50um
+micro50=find(micro_meter==50);
+plot(membPot_trBasMeanBlackSpot{micro50},'linewidth',3)
+hold on
+%80um
+micro80=find(micro_meter==80);
+plot(membPot_trBasMeanBlackSpot{micro80},'linewidth',3)
+%120um
+micro120=find(micro_meter==120);
+plot(membPot_trBasMeanBlackSpot{micro120},'linewidth',3)
+%legend
+legend({micro_meter_withLabel([micro50,micro80,micro120],:)})
+title('black spot')
+xlabel('time(ms)')
+ylabel('voltage(mV)')
+YLIM=ylim;
+
+subplot(1,2,2)
+%white spot with different sizes
+%50um
+plot(membPot_trBasMeanWhiteSpot{micro50},'linewidth',3)
+hold on
+%80um
+plot(membPot_trBasMeanWhiteSpot{micro80},'linewidth',3)
+%120um
+plot(membPot_trBasMeanWhiteSpot{micro120},'linewidth',3)
+%legend
+legend({micro_meter_withLabel([micro50,micro80,micro120],:)})
+title('white spot')
+xlabel('time(ms)')
+ylabel('voltage(mV)')
+YLIM2=ylim;
+
+%find max of the two ylims and adapt ylims to compare the two plots so that
+%they have the same ylims
+minY=min([YLIM,YLIM2])-0.5;
+maxY=max([YLIM,YLIM2])+0.5;
+subplot(1,2,1)
+ylim([minY maxY])
+subplot(1,2,2)
+ylim([minY maxY])
+
+%-------------------------------------------------------------------------------
+%% 5. add variables into the output
+uniformSpot_output.membPot_trBasMeanBlackSpot=membPot_trBasMeanBlackSpot;
+uniformSpot_output.membPot_trBasMeanWhiteSpot=membPot_trBasMeanWhiteSpot;
+uniformSpot_output.micro_meter=micro_meter;
+end

+ 189 - 0
Spot/code uniform spot/BC_uniformSpot3.m

@@ -0,0 +1,189 @@
+function [uniformSpot_output]=BC_uniformSpot3(loadData,filename,spotDuration,grayDuration,inputFrames,pathStimSignal)
+%[uniformSpot_output]=BC_uniformSpot3(loadData,filename,spotDuration,grayDuration,contrast)
+%this function shows the example analysis for the uniform spot stimulus with
+%different spot sizes for stimulus version 3. Here the black and white spot
+%are recorded in the same file
+%Inputs:
+%               loadData = the folder path of the patterned spot files
+%               filename = the filename of the BC of interest
+%               spotDuration = duration of spot in ms, found in 
+%               the excel file LogInfo_PatternedSpot.xlsx   
+%               grayDuration = duration of gray screen in ms, found in 
+%               the excel file LogInfo_PatternedSpot.xlsx 
+%               inputFrames = start and end frames of the different
+%               contrast spots, found in the excel file 
+%               LogInfo_PatternedSpot.xlsx 
+%               pathStimSignal = folder path to load the sequence of spot
+%               sizes shown
+%               
+%
+%Outpus:        uniformSpot_output = structure containing the output
+%               average membrane potential per spot size of the uniform
+%               spot for both black and white contrast.
+%
+% code by HS last modiefied March 2021
+
+%% Constants
+mircoMeter_proPixel=2.5; %one monitor pixel is 2.5 micrometers
+
+%-------------------------------------------------------------------------------
+%% 1. load the patterned spot file
+data=load([loadData,filename]); %load the file
+
+%-------------------------------------------------------------------------------
+%% 2. load the spot sizes
+%same as spot version 2
+npatterns=11; %11 spot sizes were shown
+micro_meter=[2, 6, 8, 10, 12, 16, 24, 32, 50, 100, 200 ]'*2*mircoMeter_proPixel; 
+%for plotting add the mircometer label
+micrometer_label=repmat(' \mum',size(micro_meter,1),1);
+micro_meter_withLabel=strcat (num2str(micro_meter),micrometer_label);
+
+load(pathStimSignal); %load the order of the presentation of the diameter sizes. See Documentation_Data_BCRecordings. It contains values from 10-1000 and the numbers refer to the spot size in micrometers. The same order was used for black and white spots
+
+%------------------------------------------------------------------------------------------
+%% 3. extract the membrane potential data for the black spot, for each spot size and build the average
+%start of black spot
+start_blackSpot=inputFrames(1);
+%end of black spot
+end_blackSpot=inputFrames(2);
+%only get the frames where the gray screen was shown (that you have one
+%frame per trial)
+ttls_ms_forCond=data.ttls_ms(1:2:end_blackSpot);
+
+%extract the membrane potential per spot
+membPot_perTrialBlackSpot=cell(1,npatterns);
+for j=1:npatterns %loop over spot sizes
+    spot_cond=find(stimulus==micro_meter(j));%get all the spots with same size
+    ttls_forCond=ttls_ms_forCond(spot_cond);%get the ttls signals for this circle size
+    if ~isempty(ttls_forCond)
+        %get the membrane potenial for this ttls signal (start gray screen) and go until
+        %the next spot (grayScreen 1000ms+500msSpot+1000gray)
+        for jj=1:length(ttls_forCond)
+            if length(data.membPot)>=(ttls_forCond(jj)+spotDuration-1+grayDuration*2)==1 %only if you have enought data
+                membPot_perTrialBlackSpot{j}(jj,:)=data.membPot(ttls_forCond(jj): ...
+                    (ttls_forCond(jj)+spotDuration-1+2*grayDuration)); %duration-1 -> because the next trial would start there
+            end
+        end
+    end
+    clear spot_cond ttls_forCond
+end
+
+
+% baseline on trial by trial bases -> substract from the time series of each trial
+% the mean value of the 200 ms before the spot arrives
+membPot_trBasMeanBlackSpot=cell(1,npatterns);
+basValue=-200;%amount of baseline ->200ms
+for ww=1:length(membPot_perTrialBlackSpot)%nbr of spot sizes
+    val_before=membPot_perTrialBlackSpot{ww}(:,grayDuration+basValue:grayDuration-1);
+    byTrBas_perSpot=(mean(val_before,2));
+    trBas_repMAt=repmat(byTrBas_perSpot,1, ...
+        size(membPot_perTrialBlackSpot{ww}(:,grayDuration+1:end),2)); %directly take the signal after gray screen
+    membPot_trBasMeanBlackSpot{ww}=mean(membPot_perTrialBlackSpot{ww}(:,grayDuration+1:end)- ...
+        trBas_repMAt,1);%mean for each trial, directly take the signal after gray screen
+    clear trBas_perSpotrepMAt
+end
+
+%------------------------------------------------------------------------------------------
+%% 3. extract the membrane potential data for the white spot, for each spot size and build the average
+%start of black spot
+start_whiteSpot=inputFrames(3);
+%end of black spot
+end_whiteSpot=inputFrames(4);
+%only get the frames where the gray screen was shown (that you have one
+%frame per trial)
+ttls_ms_forCond=data.ttls_ms(start_whiteSpot:2:end_whiteSpot); 
+
+%extract the membrane potential per spot
+membPot_perTrialWhiteSpot=cell(1,npatterns);
+for j=1:npatterns %loop over spot sizes
+    spot_cond=find(stimulus==micro_meter(j));%get all the spots with same size
+    ttls_forCond=ttls_ms_forCond(spot_cond);%get the ttls signals for this circle size
+    if ~isempty(ttls_forCond)
+        %get the membrane potenial for this ttls signal (start gray screen) and go until
+        %the next spot (grayScreen 1000ms+500msSpot+1000gray)
+        for jj=1:length(ttls_forCond)
+            if length(data.membPot)>=(ttls_forCond(jj)+spotDuration-1+grayDuration*2)==1 %only if you have enought data
+                membPot_perTrialWhiteSpot{j}(jj,:)=data.membPot(ttls_forCond(jj): ...
+                    (ttls_forCond(jj)+spotDuration-1+2*grayDuration)); %duration-1 -> because the next trial would start there
+            end
+        end
+    end
+    clear spot_cond ttls_forCond
+end
+
+
+% baseline on trial by trial bases -> substract from the time series of each trial
+% the mean value of the 200 ms before the spot arrives
+membPot_trBasMeanWhiteSpot=cell(1,npatterns);
+basValue=-200;%amount of baseline ->200ms
+for ww=1:length(membPot_perTrialWhiteSpot)%nbr of spot sizes
+    val_before=membPot_perTrialWhiteSpot{ww}(:,grayDuration+basValue:grayDuration-1);
+    byTrBas_perSpot=(mean(val_before,2));
+    trBas_repMAt=repmat(byTrBas_perSpot,1, ...
+        size(membPot_perTrialWhiteSpot{ww}(:,grayDuration+1:end),2)); %directly take the signal after gray screen
+    membPot_trBasMeanWhiteSpot{ww}=mean(membPot_perTrialWhiteSpot{ww}(:,grayDuration+1:end)- ...
+        trBas_repMAt,1);%mean for each trial, directly take the signal after gray screen
+    clear trBas_perSpotrepMAt
+end
+
+
+%------------------------------------------------------------------------------------------
+%% 4. Plot the data
+figure;
+%black spot
+subplot(1,2,1)
+%uniform spot, different sizes If you use earlier MATLAB versions you
+%might have to choose for each spot size a different color
+%50um
+micro50=find(micro_meter==50);
+plot(membPot_trBasMeanBlackSpot{micro50},'linewidth',3)
+hold on
+%80um
+micro80=find(micro_meter==80);
+plot(membPot_trBasMeanBlackSpot{micro80},'linewidth',3)
+%120um
+micro120=find(micro_meter==120);
+plot(membPot_trBasMeanBlackSpot{micro120},'linewidth',3)
+xlabel('time(ms)')
+ylabel('voltage(mV)')
+%legend
+legend({micro_meter_withLabel([micro50,micro80,micro120],:)})
+title('black spot')
+YLIM=ylim;
+
+%white spot
+subplot(1,2,2)
+%uniform spot, different sizes
+%50um
+micro50=find(micro_meter==50);
+plot(membPot_trBasMeanWhiteSpot{micro50},'linewidth',3)
+hold on
+%80um
+micro80=find(micro_meter==80);
+plot(membPot_trBasMeanWhiteSpot{micro80},'linewidth',3)
+%120um
+micro120=find(micro_meter==120);
+plot(membPot_trBasMeanWhiteSpot{micro120},'linewidth',3)
+%legend
+legend({micro_meter_withLabel([micro50,micro80,micro120],:)})
+title('white spot')  
+xlabel('time(ms)')
+ylabel('voltage(mV)')
+YLIM2=ylim;
+
+%find max of the two ylims and adapt ylims to compare the two plots so that
+%they have the same ylims
+minY=min([YLIM,YLIM2])-0.5;
+maxY=max([YLIM,YLIM2])+0.5;
+subplot(1,2,1)
+ylim([minY maxY])
+subplot(1,2,2)
+ylim([minY maxY])
+
+%-------------------------------------------------------------------------------
+%% 5. add variables into the output
+uniformSpot_output.membPot_trBasMean=membPot_trBasMeanBlackSpot;
+uniformSpot_output.membPot_trBasMeanWhiteSpot=membPot_trBasMeanWhiteSpot;
+uniformSpot_output.micro_meter=micro_meter;
+end

+ 84 - 0
Spot/code uniform spot/BC_uniformSpot4.m

@@ -0,0 +1,84 @@
+function [uniformSpot_output]=BC_uniformSpot4(loadData,filename,spotDuration,grayDuration)
+%[uniformSpot_output]=BC_uniformSpot4(loadData,filename,spotDuration,grayDuration)
+%this function shows the example analysis for the uniform spot stimulus with
+%different spot sizes for stimulus version 4. Here we used a reversing
+%grating
+%Inputs:
+%               loadData = the folder path of the patterned spot files
+%               filename = the filename of the BC of interest
+%               spotDuration = duration of spot in ms, found in 
+%               the excel file LogInfo_PatternedSpot.xlsx   
+%               grayDuration = duration of gray screen in ms, found in 
+%               the excel file LogInfo_PatternedSpot.xlsx 
+%               
+%
+%Outpus:        uniformSpot_output = structure containing the output
+%               average membrane potential per spot size of the reversing
+%               uniform spot
+%
+% code by HS last modiefied March 2021
+
+%% Constants
+micro_meter=[50,100,200,300,400,500]'; %spot diameter size in micro meters
+%for plotting add the mircometer label
+micrometer_label=repmat(' \mum',size(micro_meter,1),1);
+micro_meter_withLabel=strcat (num2str(micro_meter),micrometer_label);
+
+%-------------------------------------------------------------------------------
+%% 1. load the patterned spot file
+data=load([loadData,filename]); %load the file
+
+%------------------------------------------------------------------------------------------
+%% 2. extract the membrane potential data for the contrast reversing spot, for each spot size and build the average
+%get the traces, baseline them and compute the average
+membPot_perTrial=cell(size(micro_meter,1),1);   %preallocation
+membPotAVG_trBas=cell(size(micro_meter,1),1);   %preallocation
+basValue=-200;%amount of baseline in ms->last 200ms of the gray period before the spot
+
+indx=1; %start with first gray background illumination to get the baseline
+for j=1:size(micro_meter,1)
+    %get baseline before the stimulus 200ms before-> you have to do it
+    %this way because the second pulse is already the white spot -> the
+    %first black spot does not have a pulse.
+    basTemp=data.membPot(data.ttls_ms(indx)+grayDuration+basValue: ...
+        data.ttls_ms(indx)+grayDuration-1); %baseline 200ms before the start of the reversing grating
+    memPot_bas=mean(basTemp);
+    indx=indx+2; %I start  then with the second black spot -> pulse 1= gray -> pulse 2 = white spot (because first black spot doesnt get a pulse)
+    for jj=1:3 %amount of black spot start per size ->only analyse 3!
+        membPot_perTrial{j}(jj,:)=data.membPot(data.ttls_ms(indx): ...
+            data.ttls_ms(indx)+spotDuration*2-1); %duration 1000 ms for black and white together
+        indx=indx+2;
+    end
+    memPotAVG= mean(membPot_perTrial{j});
+    membPotAVG_trBas{j}= memPotAVG-memPot_bas;
+end
+
+
+
+%------------------------------------------------------------------------------------------
+%% 4. Plot the data
+figure;
+%uniform spot, different sizes. If you use earlier MATLAB versions you
+%might have to choose for each spot size a different color
+%50um
+micro50=find(micro_meter==50);
+plot(membPotAVG_trBas{micro50},'linewidth',3)
+hold on
+%100um
+micro100=find(micro_meter==100);
+plot(membPotAVG_trBas{micro100},'linewidth',3)
+%200um
+micro200=find(micro_meter==200);
+plot(membPotAVG_trBas{micro200},'linewidth',3)
+%300um
+micro300=find(micro_meter==300);
+plot(membPotAVG_trBas{micro300},'linewidth',3)
+xlabel('time(ms)')
+ylabel('voltage(mV)')
+legend({micro_meter_withLabel([micro50,micro100,micro200,micro300],:)})
+title('reversing uniform spot')
+
+%-------------------------------------------------------------------------------
+%% 5. add variables into the output
+uniformSpot_output.membPotAVG_trBas=membPotAVG_trBas;
+end