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<4 0030 quantity=1; 0031 end 0032 if nargin<5 0033 numLength=4; 0034 end 0035 0036 % Subset only existingIds that have the prefix 0037 existingIds=existingIds(~cellfun(@isempty,regexp(existingIds,['^' prefix]))); 0038 0039 if ~isempty(existingIds) 0040 existingIds=regexprep(existingIds,['^' prefix],''); 0041 existingIds=sort(existingIds); 0042 lastId=existingIds{end}; 0043 numLength=length(lastId); 0044 lastId=str2double(lastId); 0045 else 0046 lastId=0; 0047 fprintf(['No ' type ' ids with prefix "' prefix ... 0048 '" currently exist in the model. The first new id will be "' ... 0049 [prefix,num2str(1,['%0' num2str(numLength) 'd'])] '"\n'],'%s') 0050 end 0051 0052 if isnan(lastId) 0053 lastId = 0; 0054 end 0055 0056 newIds=cell(quantity,1); 0057 0058 for k=1:quantity 0059 newIds{k}=[prefix,num2str(k+lastId,['%0' num2str(numLength) 'd'])]; 0060 end 0061 end