function alignment = adjust_mult_align(alignment)

%-------------------------------------------------------------------------%
%This method evaluates previously aligned sequences with consensus sequence
%after pairwise alignment and inserts gap when needed
%-------------------------------------------------------------------------%

%Pass aligned consensus sequence into local variable
consensus_seq_aligned = alignment.temporary_pair_align(1,:);

%Count number of gaps inserted into consensus sequence
gap_index = strfind(consensus_seq_aligned, alignment.gap_symbol);

 %Check if we have ever assembled consensus sequence
    check = isempty(gap_index);
    
    %If so we will fill first sequence to be aligned with nucleotides from
    %consensus sequence, so we are sure, that multiple alignment will be
    %assembled properly
    if check ~= 1
        
        before_gap = [];
        after_gap = [];

        %Need to adjust all previously aligned sequences hence for cycle to run
        %through each of them
        for i = 1 : length(alignment.multiple_seq_alignment)

            seq_to_adjust = alignment.multiple_seq_alignment{1,i};

            for j = 1 : length(gap_index)
                
                before_gap = [];
                after_gap = [];                

                %Get position of gap
                position_gap = gap_index(j);

                %We have to cut original sequence in two
                if position_gap == 1

                    after_gap = seq_to_adjust(position_gap : end);

                elseif position_gap == length(seq_to_adjust)

                    before_gap = seq_to_adjust(1:position_gap-1);
                    %Last char on position the gap should be added to has
                    %to be moved to the last position after this inserted
                    %gap hence the need to fill after gap variable
                    after_gap = seq_to_adjust(position_gap);

                else

                    before_gap = seq_to_adjust(1 : position_gap-1);

                    %Has to increment position of gap so we do not read the same
                    %nucleotide into after_gap variable
                    after_gap = seq_to_adjust(position_gap : end);

                end

                %Lets insert gap on desired position
                seq_to_adjust = [before_gap alignment.gap_symbol after_gap];

            end

            %When particular sequence is adjuste we have to update it inside object
            %attribute
            alignment.multiple_seq_alignment{1,i} = seq_to_adjust;

        end

end