function alignment = sum_of_pairs(alignment)

%Pass all of aligned sequences into local variable
for i = 1 : length(alignment.multiple_seq_alignment) 
    alignment_tmp(i,:) =  alignment.multiple_seq_alignment{1,i};
end

%clear previously used variable
clear i

score = 0;

is_gap = '0';

%We have to serach all columns in aligned sequences hence run cycle for
%length of alignment
for i = 1 : length(alignment_tmp)
    
%   get actual column
    column = alignment_tmp(:,i);
    
    %For symbol in column we have to count its score with another symbol
        for j = 1 : length(column)
    
            actual_char_01 = column(j);
            
            if actual_char_01 == 'A'

                  sub_seq2=1;

              elseif actual_char_01 == 'C'

                  sub_seq2=2;

              elseif actual_char_01 == 'G'

                  sub_seq2=3;

              elseif actual_char_01 == 'T'

                  sub_seq2=4;
                  
            else
                
                is_gap = 'X';

            end

                for k = j : length(column)
                    
                        if k < length(column)

                        %If first symbol is gap we have no need to initialize
                        %another variables, since it will always has value of
                        %gap
                            if is_gap == 'X';

                                score = score + alignment.gap;

                            else

                            actual_char_02 = column(k + 1);

                                if actual_char_02 == 'A'

                                      sub_seq1=1;

                                  elseif actual_char_02 == 'C'

                                      sub_seq1=2;

                                  elseif actual_char_02 == 'G'

                                      sub_seq1=3;

                                  elseif actual_char_02 =='T'

                                      sub_seq1=4;

                                end

                                score = score + alignment.scoring_matrix(sub_seq1,sub_seq2);

                            end
                    
                        end
                
                end
                
                is_gap = '0';
                
        end
        
end

alignment.score = score;