https://github.com/huguenardlab/fiberphotometry
Raw File
Tip revision: 70d31d43686fdd0577bf1903dccfa544327b375a authored by huguenardlab on 22 March 2023, 17:15:05 UTC
Add files via upload
Tip revision: 70d31d4
cleanUpOperantData.m
%--------------------------------------------------------------------------
%cleanUpOperantData
%By: Brielle Ferguson
%Date: 5/11/19
%Function will take serial monitor data from an Arduino operant data session, and remove the
%clean ports trial from the beginning, and any additional nose pokes in the
%center port following trial initiation. Without this step, the
%readAnalyzePlotBehData function (which calls this function) will generate errors 
%Assumptions:
% - data is a cell array generated by StreamAndSaveSMData
%%inputs: 
% - data: cell array generated by function above
%outputs: 
% - newData: cell array missing any trials that would be generate errors for the
% analysis function
%--------------------------------------------------------------------------


function [newData] = cleanUpOperantData(data)
newData = {}; 
match1 = 'Clean Ports';
match2 = 'Center Initiation Port Entry';
match3 = 'Session';
match4 = 'Performance Summary:';
match5 = 'Number of Trials:';
match6 = 'Left Choices:';
match7 = 'Right Choices:';
match8 = 'Correct Choices:';
match9 = 'Incorrect Choices:';
match10 = 'ommand';
match11 = 'Trial Available';
match12 = 'LED';
match13 = '100 Trials Completed';
match14 = 'Time';
match15 = 'Entries';
match16 = 'Center Port Entry';
match17 = 'Optogenetic Stim';

%will search each line in the behData for array for the matches listed above if
%any of these are not removed from data will cause errors in the analysis script
for i = 1: length(data)
    
   string = char(data(i));
   if contains(string, match1)|| contains(string, match2) || contains(string, match3)...
           || contains(string, match4) || contains(string, match5) || contains(string, match6)...
           || contains(string, match7) || contains(string, match8) || contains(string, match9)...
           || contains(string, match10) || contains(string, match12) || contains(string, match13)...
           || contains(string, match14)  || contains(string, match15)
       newData(i) = {[]};
   else
       newData(i) = {string}; 
   end
   
end

newData = transpose(newData(~cellfun('isempty',newData)));

%do a final check of the last trial info and remove if it contains matches to trial types
%which will generate an error
string = char(newData(end)); 

if contains(string, match11) 
    newData = newData(1:end-1);
end

if contains(string, match16) 
    newData = newData(1:end-2);
end

if contains(string, match17) 
    newData = newData(1:end-3);
end

end



back to top