Skip to content

Commit

Permalink
fix: ravenCobraWrapper variations on cobra fields
Browse files Browse the repository at this point in the history
  • Loading branch information
edkerk committed Feb 13, 2024
1 parent 8fe29c6 commit d737363
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
5 changes: 5 additions & 0 deletions io/writeYAMLmodel.m
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ function writeField(model,fid,fieldName,type,pos,name,preserveQuotes)
list = ['"' list{1} '"'];
end
fprintf(fid,' %s: %s\n',name,list);
elseif ischar(list) && strcmp(fieldName,'subSystems')
if preserveQuotes
list = ['"' list '"'];
end
fprintf(fid,' %s: %s\n',name,list);
elseif length(list) > 1 || strcmp(fieldName,'subSystems')
if preserveQuotes
for j=1:numel(list)
Expand Down
32 changes: 14 additions & 18 deletions struct_conversion/ravenCobraWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,24 @@
%Mandatory RAVEN fields
newModel.mets=model.mets;
if ~isfield(model,'comps')
model.comps = unique(regexprep(model.mets,'.*\[([^\]]+)\]$','$1'));
%Since 'comps' field is not mandatory in COBRA, it may be required
%to obtain the non-redundant list of comps from metabolite ids, if
%'comps' field is not available
newModel.comps = unique(regexprep(model.mets,'.*\[([^\]]+)\]$','$1'));
newModel.compNames = newModel.comps;
end
for i=1:numel(model.comps)
newModel.mets=regexprep(newModel.mets,['\[', model.comps{i}, '\]$'],'');
newModel.mets=regexprep(newModel.mets,['\[', model.compNames{i}, '\]$'],'');
for i=1:numel(newModel.comps)
newModel.mets=regexprep(newModel.mets,['\[', newModel.comps{i}, '\]$'],'');
newModel.mets=regexprep(newModel.mets,['\[', newModel.compNames{i}, '\]$'],'');
end

%In some cases (e.g. any model that uses BiGG ids as main ids), there
%may be overlapping mets due to removal of compartment info. To avoid
%this, we change compartments from e.g. [c] into _c
if numel(unique(newModel.mets))~=numel(model.mets)
newModel.mets=model.mets;
for i=1:numel(model.comps)
newModel.mets=regexprep(newModel.mets,['\[' model.comps{i} '\]$'],['_' model.comps{i}]);
for i=1:numel(newModel.comps)
newModel.mets=regexprep(newModel.mets,['\[' newModel.comps{i} '\]$'],['_' newModel.comps{i}]);
end
end
%Since COBRA no longer contains rev field it is assumed that rxn is
Expand All @@ -237,15 +241,7 @@
end
end
newModel.b=zeros(numel(model.mets),1);
if ~isfield(model,'comps')
%Since 'comps' field is not mandatory in COBRA, it may be required
%to obtain the non-redundant list of comps from metabolite ids, if
%'comps' field is not available
newModel.comps=regexprep(model.mets,'^.+\[','');
newModel.comps=regexprep(newModel.comps,'\]$','');
newModel.comps=unique(newModel.comps);
end


%metComps is also mandatory, but defined later to match the order of
%fields

Expand Down Expand Up @@ -331,9 +327,9 @@
newModel.geneShortNames=model.geneNames;
end
newModel.metNames=model.metNames;
for i=1:numel(model.comps)
newModel.metNames=regexprep(newModel.metNames,['\[', model.comps{i}, '\]$'],'');
newModel.metNames=regexprep(newModel.metNames,['\[', model.compNames{i}, '\]$'],'');
for i=1:numel(newModel.comps)
newModel.metNames=regexprep(newModel.metNames,['\[', newModel.comps{i}, '\]$'],'');
newModel.metNames=regexprep(newModel.metNames,['\[', newModel.compNames{i}, '\]$'],'');
end
newModel.metNames=deblank(newModel.metNames);
newModel.metComps=regexprep(model.mets,'^.+\[','');
Expand Down

0 comments on commit d737363

Please sign in to comment.