function NEW_INDS = Align2Ref(REF_SEQ, ALIGN, ALIGN_INDS, ALPHA)
%   Align2Ref
%       Uses a profile alignment to change a set of indicices in the
%       "alignment space" to the "reference space".
%
%
%   NEW_INDS = Align2Ref(REF_SEQ, ALIGN, ALIGN_INDS)
%

if nargin == 3
    ALPHA = 'aa';
end

ref_prof = seqprofile(REF_SEQ, 'alphabet', ALPHA);
align_prof = seqprofile(ALIGN, 'alphabet', ALPHA);

[~, ind1, ind2] = profalign(ref_prof, align_prof);

ninds = ind2(ALIGN_INDS);

mask = sum(bsxfun(@le, ind1(:)', ninds(:)),2);
mask(mask == 0) = 1;

NEW_INDS = reshape(ind1(mask), size(ALIGN_INDS));