% Prepare sensitized hemo experiment
% Expected input = one .mat file, one corresponding survival worksheet

%% Options

% Directory to look in when selecting data file
baseDir = "D:\Harvard\Summit behavior\";
dataDir = strcat(baseDir,"Behavior data\");
analysisDir = strcat(baseDir,"Analysis\");

doDenoise = 0;      % option to denoise data
doCallROI = 1;    % option to call start time and whether ROI is viable
callFirst = 1;          % call first frame of fly movement
callViablility = 1;     % call whether fly was viable?
useKnownBounds = 0;     % do you want to use expected well height (based on adjacent wells) to normalize y position?


%% Select input .mat file

% Check if files have been previously loaded (still in memory)
% Ask if user wants to select new files or use what's saved in convFiles
if exist('convFiles','var')
    [convFiles,fileChoice] = decideIfSelectNewFiles(convFiles);
else
    convFiles = [];
    fileChoice = "Yes";
end

if strcmp(fileChoice,'Yes') || isempty(convFiles)
    convFiles = selectMatFiles(dataDir);
end

%% Convert .mat file if not yet converted
convFiles = convertMargo(convFiles);

%% Denoise .mat file if desired
if doDenoise
    convFiles = autoDenoise(convFiles, 40, 20);
end

%% Call time of first movement

if doCallROI
    callHemoStart(convFiles,callFirst,callViablility,useKnownBounds)
end
