forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkCobraModelUnique.m
56 lines (53 loc) · 1.81 KB
/
checkCobraModelUnique.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function model = checkCobraModelUnique(model,renameFlag)
%checkCobraModelUnique Check uniqueness of reaction and metabolite names
%
% model = checkCobraModelUnique(model,renameFlag)
%
%INPUT
% model COBRA model structure
%
%OPTIONAL INPUT
% renameFlag Renames non-unique reaction names and metabolites
% (Default = false)
%
%OUTPUT
% model COBRA model structure
%
% Markus Herrgard 10/17/07
if (nargin < 2)
renameFlag = false;
end
[rxnName,rxnCnt] = countUnique(model.rxns);
rxnInd = find(rxnCnt > 1);
if ~isempty(rxnInd)
fprintf('Model contains non-unique reaction names - consider renaming reactions using checkCobraModelUnique\n');
for i = 1:length(rxnInd)
thisRxnName = rxnName{rxnInd(i)};
fprintf('%s\t%d\n',thisRxnName,rxnCnt(rxnInd(i)));
if (renameFlag)
fprintf('Renaming non-unique reactions\n');
rxnIDs = findRxnIDs(model,thisRxnName);
for j = 1:length(rxnIDs)
model.rxns{rxnIDs(j)} = [thisRxnName '_' num2str(j)];
fprintf('%s\n',model.rxns{rxnIDs(j)});
end
end
end
end
[metName,metCnt] = countUnique(model.mets);
metInd = find(metCnt > 1);
if ~isempty(metInd)
fprintf('Model contains non-unique metabolite names - consider renaming metabolites using checkCobraModelUnique\n');
for i = 1:length(metInd)
thisMetName = metName{metInd(i)};
fprintf('%s\n',thisMetName);
if (renameFlag)
fprintf('Renaming non-unique metabolites\n');
rxnIDs = findRxnIDs(model,thisMetName);
for j = 1:length(rxnIDs)
model.rxns{rxnIDs(j)} = [thisMetName '_' num2str(j)];
fprintf('%s\n',model.mets{rxnIDs(j)});
end
end
end
end