%% 
clear
clear global
%% Initialize

initializeFunction(false, false, false)


%% To be done before it all runs
% Ask the user to draw circle to define OneCell Area on first image
disp('Waiting for user input for oneCellArea')
global segmentationIndexes trackingIndexes nbMovies mainFunctionFolder trackAssemblyIndexes predictionIndexes trainingIndexes


if ~isempty(segmentationIndexes) || ~isempty(trackingIndexes)
    oneCellArea = ones(nbMovies,1).*500;
    for m = unique(transpose([segmentationIndexes; trackingIndexes]))
        [oneCellArea(m),sameForOther] = drawOneCellArea(m);
        if sameForOther == 1
            oneCellArea(m+1:end) = oneCellArea(m);
            break
        end
    end
    %disp(oneCellArea)
    save(fullfile(mainFunctionFolder, 'oneCellArea.mat'), 'oneCellArea');
end



%% Setup paralell pool
if ~isempty(segmentationIndexes) || ~isempty(trackingIndexes) || ~isempty(trackAssemblyIndexes) || ~isempty(predictionIndexes) || ~isempty(trainingIndexes) 
    if isempty(gcp('nocreate'))
        A = parcluster('local');
        parpool(A.NumWorkers);
    end
end
%% Segmentation 
if ~isempty(segmentationIndexes)
    A_Segmentation;
end 

%% Tracking 
if ~isempty(trackingIndexes)
    A_Tracking;
end

%% TrackAnalysis
if ~isempty(trackAssemblyIndexes)
    A_TrackAssembly;

end
checkGT_AgSpe 
updateAgSpeRatio
manualLabelling
updateActRatio
