function annotation = changeId(annotation, id_1, id_2)
%
% annotation = changeId(annotation, id_1, id_2)
%
% changes id_1 into id_2

if isfield(annotation, 'object')
    if nargin == 1
        id_1 = [annotation.object.id];
        id_2 = 0:length(id_1)-1;
    end
    
    for i = 1:length(annotation.object)
        % replace object id
        id = annotation.object(i).id;
        j = find(id_1==id);
        annotation.object(i).id = id_2(j);
        
        % replace field parts
        if isfield(annotation.object(i), 'parts')
            if isfield(annotation.object(i).parts, 'ispartof')
                [f, ispartof] = ismember(str2num(annotation.object(i).parts.ispartof), id_1);
                ispartof = ispartof(f);
                tmp=num2str(id_2(ispartof),'%d,'); tmp = tmp(1:end-1);
                annotation.object(i).parts.ispartof = tmp;
            end
            if isfield(annotation.object(i).parts, 'hasparts')
                [f, hasparts] = ismember(str2num(annotation.object(i).parts.hasparts), id_1);
                hasparts = hasparts(f);
                tmp=num2str(id_2(hasparts),'%d,'); tmp = tmp(1:end-1);
                annotation.object(i).parts.hasparts = tmp;
            end
        end
    end
end


