generateNewIds Generates a list of new metabolite or reaction ids, sequentially numbered with a defined prefix. The model is queried for the highest existing number of that type of id. model model structure type string specifying type of id, 'rxns' or 'mets' prefix string specifying prefix to be used in all ids. E.g. 's_' or 'r_'. quantity number of new ids that should be generated (optional, default 1) numLength length of numerical part of id. E.g. 4 gives ids like r_0001 and 6 gives ids like r_000001. If the prefix is already used in the model, then the model-defined length will be used instead. (optional, default 4) Usage: newIds=generateNewIds(model,type,prefix,quantity,numLength)
0001 function newIds=generateNewIds(model,type,prefix,quantity,numLength) 0002 % generateNewIds 0003 % Generates a list of new metabolite or reaction ids, sequentially 0004 % numbered with a defined prefix. The model is queried for the highest 0005 % existing number of that type of id. 0006 % 0007 % model model structure 0008 % type string specifying type of id, 'rxns' or 'mets' 0009 % prefix string specifying prefix to be used in all ids. E.g. 's_' 0010 % or 'r_'. 0011 % quantity number of new ids that should be generated (optional, default 1) 0012 % numLength length of numerical part of id. E.g. 4 gives ids like 0013 % r_0001 and 6 gives ids like r_000001. If the prefix is 0014 % already used in the model, then the model-defined length 0015 % will be used instead. (optional, default 4) 0016 % 0017 % Usage: newIds=generateNewIds(model,type,prefix,quantity,numLength) 0018 % 0019 type=char(type); 0020 prefix=char(prefix); 0021 0022 if type=='rxns' 0023 existingIds=model.rxns; 0024 elseif type=='mets' 0025 existingIds=model.mets; 0026 else 0027 error('type should be either ''rxns'' or ''mets''.') 0028 end 0029 if nargin<5 0030 numLength=4; 0031 end 0032 0033 % Subset only existingIds that have the prefix 0034 existingIds=existingIds(~cellfun(@isempty,regexp(existingIds,['^' prefix]))); 0035 0036 if ~isempty(existingIds) 0037 existingIds=regexprep(existingIds,['^' prefix],''); 0038 existingIds=sort(existingIds); 0039 lastId=existingIds{end}; 0040 numLength=length(lastId); 0041 lastId=str2double(lastId); 0042 else 0043 lastId=0; 0044 fprintf(['No ' type ' ids with prefix "' prefix ... 0045 '" currently exist in the model. The first new id will be "' ... 0046 [prefix,num2str(1,['%0' num2str(numLength) 'd'])] '"\n'],'%s') 0047 lastId=0; 0048 end 0049 0050 newIds=cell(quantity,1); 0051 0052 for k=1:quantity 0053 newIds{k}=[prefix,num2str(k+lastId,['%0' num2str(numLength) 'd'])]; 0054 end 0055 end