function [c1, c2] = alignCoords(crd1, s1, crd2, s2) %ALIGNCOORDS Align coordinates of amino acids in correspondece with % the sequence alignment. % [C1, C2] = alignCoords(CRD1, S1, CRD2, S2), where CRD1 and CRD2 % are the original coordinate matrices, S1 and S2 are the aligned % sequences, and C1 and C2 are coordinate matrices corresponding to % the sequence alignment of s1 and s2. if (length(s1) ~= length(s2)) error('Aligned sequences must have the same length'); end c1 = []; index1 = 0; c2 = []; index2 = 0; j = 0; n = length(s1); for i=1:n if (s1(i) ~= '-' & s2(i) ~= '-') % Two amino acids aligned against each other index1 = index1 + 1; % Align the corresponding coordinates index2 = index2 + 1; % against one another j = j + 1; % j is the current length of the either c1(j, :) = crd1(index1, :); % aligned coordinate matrix c2(j, :) = crd2(index2, :); elseif (s1(i) == '-') % Amino acid is s2 aligned against gap in s1 index2 = index2 + 1; % Skip corresponding coordinate in s2 else % Amino acid is s1 aligned against gap in s2 index1 = index1 + 1; % Skip corresponding coordinate in s1 end end