Contents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Acquisition of data, 1 if it's needed 0 if it is not necessary
Acquisition_Data = 0;

Clear and close everything before compile (avoid any errors due to possibile overwritings

%Boolean needed:
%Acquisition_Data

if Acquisition_Data
    clc
    close all
    clear
    Acquisition_Data = 1;
end

if Acquisition_Data
    %Script for acquiring the cells' centroid
    [Cell, number_of_cells, Cell_name_boolean] = Cells_centroid_info_acquirer();
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Plot of the Centroids of the cell acquired from the Excel files, set 1 if one want the plots, 0 otherwise. Animation is the boolean for the optional plot of the path animated from the start to the end of the cell movement (time is referred as time unit)

plot_centroids = 0;
Animation = 1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%Booleans for the Beauchemin section%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Strings of all the statistics present that can be computed

Str_statistics = {'MD', 'MSD', 'V', 'Vx', 'Vy'};

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Acquisition of statistics: 1 means will acquire, 0 will not

A_MD  = 1;
A_MSD = 1;
A_V   = 1;
A_Vx  = 0;
A_Vy  = 0;

IF any of speeds (Vx, Vy or V) are acquired then histogram are needed for the analysis it/them.

% Value for how many subclasses one want foe the hystogram
interval = 25;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Section needed IF you want to plot all the graphs of a particular

statistic of all the cell (set plot_all_graphs to 1, set it to 0 if it's not needed)

Possible choice of feature are 'MD', 'MSD', 'Vx', 'Vy', 'V'

%Furthermore, you can choose to visualize in a plot or in loglog scale
plot_all_graphs = 0;
feature = 'MD';
plot_feature_loglog = 1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Section neeeded If you want to plot all the graphs of all the statistics desired of a particular cell (put the cell number in terms of how it is saved in the Workspace).

Ex: if 1st cell is cell_1, 2nd cell is cell_11 and 3rd cell is cell_101 If you want all the info of statistics of your interest on cell_101 SET Cell_of_choice = 3, if these plots are not needed, just set Cell_ofchoice = 0)

Cell_of_choice = 1;
plot_feature_loglog = 1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Plot of the centroids

%Boolean needed:
%plot_centroids
%Animation

if plot_centroids
    for j = 1:number_of_cells
        figure(j)
        plot_centroids_path(Cell,Cell_name_boolean(j), Animation);

    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%STATISTICS FOR THE BEAUCHEMIN MODEL%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Acquisition of the features MD and/or MSD

%boolean needed:
%A_MD
%A_MSD

if A_MD && A_MSD

    for i= 1:number_of_cells

        Cell_Steps = zeros(number_of_cells,1);

        for j = 1:number_of_cells
            Cell_Steps(j) = max(size(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).cX));
        end

        [Cell.(['cell_', num2str(Cell_name_boolean(i)), '_info']).MD, ...
         Cell.(['cell_', num2str(Cell_name_boolean(i)), '_info']).MSD] = Calculate_MD_MSD(Cell,Cell_name_boolean(i),Cell_Steps(i));
    end
else
    if A_MD
        for i= 1:number_of_cells

            Cell_Steps = zeros(number_of_cells,1);

            for j = 1:number_of_cells
                Cell_Steps(j) = max(size(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).cX));
            end

            Cell.(['cell_', num2str(Cell_name_boolean(i)), '_info']).MD = Calculate_MD(Cell,Cell_name_boolean(i),Cell_Steps(i));
        end

    elseif A_MSD % Acquisition of only MSD
        for i= 1:number_of_cells

            Cell_Steps = zeros(number_of_cells,1);

            for j = 1:number_of_cells
                Cell_Steps(j) = max(size(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).cX));
            end

            Cell.(['cell_', num2str(Cell_name_boolean(i)), '_info']).MSD = Calculate_MSD(Cell,Cell_name_boolean(i),Cell_Steps(i));
        end
    else %otherwise
    end
end

Acquisition of the features Vx and/or Vy or V+Vx+Vy

%Boolean needed:
%A_Vx
%A_Vy
%A_V

if A_V

    for i= 1:number_of_cells

        Cell_Steps = zeros(number_of_cells,1);

        for j = 1:number_of_cells
            Cell_Steps(j) = max(size(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).cX));
        end

       [ Cell.(['cell_', num2str(Cell_name_boolean(i)), '_info']).Vx, ...
         Cell.(['cell_', num2str(Cell_name_boolean(i)), '_info']).Vy, ...
         Cell.(['cell_', num2str(Cell_name_boolean(i)), '_info']).V ] = Calculate_V(Cell,Cell_name_boolean(i),Cell_Steps(i));
    end

else
    if A_Vx || A_Vy
        if A_Vx
            for i= 1:number_of_cells

                Cell_Steps = zeros(number_of_cells,1);

                for j = 1:number_of_cells
                    Cell_Steps(j) = max(size(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).cX));
                end

                Cell.(['cell_', num2str(Cell_name_boolean(i)), '_info']).Vx = Calculate_Vx(Cell,Cell_name_boolean(i),Cell_Steps(i));
            end
        end
        if A_Vy % Acquisition of only Vy
            for i= 1:number_of_cells

                Cell_Steps = zeros(number_of_cells,1);

                for j = 1:number_of_cells
                    Cell_Steps(j) = max(size(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).cX));
                end

                Cell.(['cell_', num2str(Cell_name_boolean(i)), '_info']).Vy = Calculate_Vy(Cell,Cell_name_boolean(i),Cell_Steps(i));
            end
        end
    end
end

Estimate the values for a possible power law of the features

%String needed:
%Str_statistics = {'MD', 'MSD', 'Vx', 'Vy', 'V'};

for i = 1:length(Str_statistics)

 if eval(['A_',Str_statistics{i}])

    if i<=2

        Cell.(['gamma_',Str_statistics{i}]) = zeros(1,number_of_cells);

        for j = 1:number_of_cells

            [ Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'_gamma']), ...
              Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'_alpha']) ...
            ] = ...
                linear_regression(Cell, Cell_name_boolean(j), Cell_Steps(j), Str_statistics{i});

            Cell.(['gamma_',Str_statistics{i}])(j) = ...
            Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'_gamma']);
        end

     elseif i==3

        [ Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'_frequency']), ...
          Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'_speed']) ...
        ] = hist(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).(Str_statistics{i}),interval);
        [ Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'x_frequency']), ...
          Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'x_speed']) ...
        ] = hist(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).(Str_statistics{i}),interval);
        [ Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'y_frequency']), ...
          Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'y_speed']) ...
        ] = hist(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).(Str_statistics{i}),interval);


    elseif i==4

        [ Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'_frequency']), ...
          Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'_speed']) ...
        ] = hist(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).(Str_statistics{i}),interval);

    elseif i==5

        [ Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'_frequency']), ...
          Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([Str_statistics{i},'_speed']) ...
        ] = hist(Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).(Str_statistics{i}),interval);

    end
 end
end

Plot of all the graphs of a particular feature

%Boolean value needed:
%plot_all_graphs = 0;
%plot_feature_loglog = 1;
%feature = 'MD';

if plot_all_graphs
    for j = 1:number_of_cells
        if ~strcmp(feature, 'MD') && ~strcmp(feature, 'MSD')
            Cell.(['cell_', num2str(Cell_name_boolean(Cell_of_choice)), '_info']).([Str_statistics{i},'_gamma'])  = 0;
            Cell.(['cell_', num2str(Cell_name_boolean(Cell_of_choice)), '_info']).([Str_statistics{i}, '_alpha']) = 0;
        end
        figure(j)
        plot_one_statistic( Cell, Cell_name_boolean(j),Cell_Steps(j), feature,  plot_feature_loglog , ...
                            Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([feature,'_gamma']), ...
                            Cell.(['cell_', num2str(Cell_name_boolean(j)), '_info']).([feature, '_alpha']), interval ...
                          );
    end

end

Plots of all the calculated statistics of a particular cell of choice

%Boolean value needed:
%Cell_of_choice = 1;
%plot_feature_loglog = 1;

if Cell_of_choice>=1
    fig = 1;
    for i = 1:length(Str_statistics)      %Check of all the statistics were calculated
        if eval(['A_',Str_statistics{i}]) %Check if the statistic of interest was calculated
            fig = fig + 1;
            figure(fig)

            if i>=3
               Cell.(['cell_', num2str(Cell_name_boolean(Cell_of_choice)), '_info']).([Str_statistics{i},'_gamma'])  = 0;
               Cell.(['cell_', num2str(Cell_name_boolean(Cell_of_choice)), '_info']).([Str_statistics{i}, '_alpha']) = 0;
            end

            plot_one_statistic(Cell, Cell_name_boolean(Cell_of_choice), Cell_Steps(Cell_of_choice), Str_statistics{i}, plot_feature_loglog, ...
                               Cell.(['cell_', num2str(Cell_name_boolean(Cell_of_choice)), '_info']).([Str_statistics{i},'_gamma']), ...
                               Cell.(['cell_', num2str(Cell_name_boolean(Cell_of_choice)), '_info']).([Str_statistics{i}, '_alpha']), interval ...
                );
        end
    end
end

%%%% Need to estimate v_free, t_free, t_pause via fitting of the mean
%%%% displacement data, maybe look at the Beauchemin's article...