Skip to content

Commit

Permalink
feat: fix subSystems field
Browse files Browse the repository at this point in the history
Fixed all the functions involving subSystems field. Also fixed KEGG, MetaCyc and HMR databases, since the Matlab structures with subSystems as cell array columns of string are no longer compatible with export functions.
  • Loading branch information
Simonas Marcišauskas committed Mar 19, 2018
1 parent ab6f3c9 commit 6f29d82
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 32 deletions.
8 changes: 4 additions & 4 deletions core/FSEOF.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%
% Usage: targets=FSEOF(model,biomassRxn,targetRxn,iterations,coefficient,outputFile)
%
% Eduard Kerkhoven, 2017-12-21
% Simonas Marcisauskas, 2018-03-18

if nargin<4
iterations=10;
Expand Down Expand Up @@ -98,9 +98,9 @@
formatSpec='%s\t%s\t%s\t%s\t%s\t%s\t%s\n';
if output == 1 %Output to a file
fid=fopen(outputFile,'w');
fprintf(fid,formatSpec,'Slope','rowID','Enzyme ID','Enzyme Name','Subsystem','Direction','Gr Rule');
fprintf(fid,formatSpec,'Slope','rowID','Enzyme ID','Enzyme Name','Subsystems','Direction','Gr Rule');
else %Output to screen
fprintf(formatSpec,'Slope','rowID','Enzyme ID','Enzyme Name','Subsystem','Direction','Gr Rule');
fprintf(formatSpec,'Slope','rowID','Enzyme ID','Enzyme Name','Subsystems','Direction','Gr Rule');
end

for num=1:length(fseof.target)
Expand All @@ -109,7 +109,7 @@
A1=num2str(num); %row ID
A2=char(model.rxns(num)); %enzyme ID
A3=char(model.rxnNames(num)); %enzyme Name
A4=char(model.subSystems(num)); %Subsystem
A4=char(strjoin(model.subSystems{num,1},';')); %Subsystems
A5=num2str(model.rev(num)*rxnDirection(num,1)); %reaction Dirction
A6=char(model.grRules(num)); %Gr Rule
if output == 1 %Output to a file
Expand Down
10 changes: 6 additions & 4 deletions core/checkModelStruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function checkModelStruct(model,throwErrors,trimWarnings)
%
% Usage: checkModelStruct(model,throwErrors,trimWarnings)
%
% Simonas Marcisauskas, 2018-03-17
% Simonas Marcisauskas, 2018-03-18
%

if nargin<2
Expand Down Expand Up @@ -149,9 +149,11 @@ function checkModelStruct(model,throwErrors,trimWarnings)
end
end
if isfield(model,'subSystems')
if ~iscellstr(model.subSystems)
EM='The "subSystems" field must be a cell array';
dispEM(EM,throwErrors);
for i=1:numel(model.subSystems)
if ~iscell(model.subSystems{i,1})
EM='The "subSystems" field must be a cell array';
dispEM(EM,throwErrors);
end
end
end
if isfield(model,'eccodes')
Expand Down
16 changes: 13 additions & 3 deletions core/sortModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%
% Usage: model=sortModel(model,sortReversible,sortMetName,sortReactionOrder)
%
% Rasmus Agren, 2014-01-09
% Simonas Marcisauskas, 2018-03-19
%

if nargin<2
Expand Down Expand Up @@ -65,10 +65,20 @@
dispEM(EM);
end

subsystems=unique(model.subSystems);
subsystemsUnique='';
subsystemsConcatenated='';
for i=1:numel(model.subSystems)
subsystemsConcatenated{i,1}=strjoin(model.subSystems{i,1},';');
if ~isempty(model.subSystems{i,1})
for j=1:numel(model.subSystems{i,1})
subsystemsUnique{numel(subsystemsUnique)+1,1}=model.subSystems{i,1}{1,j};
end
end
end
subsystemsUnique=unique(subsystemsUnique);
for i=1:numel(subsystems)
%Get all reactions for that subsystem
rxns=find(ismember(model.subSystems,subsystems(i)));
rxns=find(~cellfun(@isempty,regexp(subsystemsConcatenated,subsystemsUnique(i))));

%Temporarily ignore large subsystems because of inefficient
%implementation
Expand Down
Binary file modified external/hmr/HMRdatabase2_00.mat
Binary file not shown.
21 changes: 11 additions & 10 deletions external/kegg/getRxnsFromKEGG.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
%
% Usage: model=getRxnsFromKEGG(keggPath,keepUndefinedStoich,keepIncomplete,keepGeneral)
%
% Simonas Marcisauskas, 2017-05-02
% Simonas Marcisauskas, 2018-03-19
%

%NOTE: This is how one entry looks in the file
Expand Down Expand Up @@ -236,17 +236,18 @@
pathway=true;
end

%Don't do this if the pathway is rn01100 (Metabolic pathways)
if ~strcmp('rn01100',tempStruct.value{addToIndex,1})
%Don't save global or overview pathways. The
%ids for such pathways begin with rn011 or rn012;
if ~strcmp('rn011',tempStruct.value{addToIndex,1}(1:5)) && ~strcmp('rn012',tempStruct.value{addToIndex,1}(1:5))
model.rxnMiriams{rxnCounter}=tempStruct;

%Also save the subSystems entry as being the first path found
if ~any(model.subSystems{rxnCounter})
if strcmp(tline(14:17),'PATH:')
model.subSystems{rxnCounter}=tline(28:end);
else
model.subSystems{rxnCounter}=tline(22:end);
end
%Also save the subSystems names. For the old KEGG
%format, only the first mentioned subsystem is picked.
%Use the newer KEGG format to fetch all the subsystems;
if strcmp(tline(14:17),'PATH:')
model.subSystems{rxnCounter}=tline(28:end);%The old format;
else
model.subSystems{rxnCounter,1}{1,numel(model.subSystems{rxnCounter,1})+1}=tline(22:end);%The new format;
end
end
end
Expand Down
Binary file modified external/kegg/keggRxns.mat
Binary file not shown.
8 changes: 2 additions & 6 deletions external/metacyc/getRxnsFromMetaCyc.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
%
% Usage: model=getRxnsFromMetaCyc(metacycPath,keepTransportRxns,keepUnbalanced,keepUndetermined)
%
% Hao Wang, 2017-11-15
% Simonas Marcisauskas, 2018-03-19
%

%NOTE: This is how one entry looks in the file
Expand Down Expand Up @@ -278,11 +278,7 @@

[x, y]=ismember(tline(14:end),pwys);
if x
if isempty(metaCycRxns.subSystems{rxnCounter})
metaCycRxns.subSystems{rxnCounter}=pwyNames{y};
else
metaCycRxns.subSystems{rxnCounter}=strcat(metaCycRxns.subSystems{rxnCounter},';',pwyNames{y});
end
metaCycRxns.subSystems{rxnCounter,1}{1,numel(metaCycRxns.subSystems{rxnCounter,1})+1}=pwyNames{y};
end
end

Expand Down
Binary file modified external/metacyc/metaCycRxns.mat
Binary file not shown.
7 changes: 5 additions & 2 deletions io/exportToExcelFormat.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function exportToExcelFormat(model,filename)
%
% Usage: exportToExcelFormat(model,filename)
%
% Simonas Marcisauskas, 2017-09-12
% Simonas Marcisauskas, 2018-03-18
%

[~, A, B]=fileparts(filename);
Expand Down Expand Up @@ -164,7 +164,10 @@ function exportToExcelFormat(model,filename)
rxnSheet=[rxnSheet rxnMiriams];

if isfield(model,'subSystems')
rxnSheet=[rxnSheet model.subSystems];
for i=1:numel(model.subSystems)
subsystems{i,1}=strjoin(model.subSystems{i,1},';');
end
rxnSheet=[rxnSheet subsystems];
else
rxnSheet=[rxnSheet emptyColumn];
end
Expand Down
4 changes: 2 additions & 2 deletions io/exportToTabDelimited.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function exportToTabDelimited(model,path)
%
% Usage: exportToTabDelimited(model,path)
%
% Simonas Marcisauskas, 2018-03-17
% Simonas Marcisauskas, 2018-03-18

if nargin<2
path='./';
Expand Down Expand Up @@ -99,7 +99,7 @@ function exportToTabDelimited(model,path)
end

if isfield(model,'subSystems')
fprintf(rxnFile,[model.subSystems{i} '\t']);
fprintf(rxnFile,[strjoin(model.subSystems{i,1},';') '\t']);
else
fprintf(rxnFile,'\t');
end
Expand Down
5 changes: 4 additions & 1 deletion io/importExcelModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
case 9
model.rxnComps=cellfun(@toStr,raw(2:end,I(i)),'UniformOutput',false);
case 10
model.subSystems=cellfun(@toStr,raw(2:end,I(i)),'UniformOutput',false);
subsystems=cellfun(@toStr,raw(2:end,I(i)),'UniformOutput',false);
case 11
reactionReplacement=cellfun(@toStr,raw(2:end,I(i)),'UniformOutput',false);
case 12
Expand All @@ -420,6 +420,9 @@
if ~isempty(model.rxnConfidenceScores)
model.rxnConfidenceScores=str2double(model.rxnConfidenceScores);
end
for i=1:numel(subsystems)
model.subSystems{i,1}=cellstr(strsplit(subsystems{i,1},';'));
end;

%Check that all necessary reaction info has been loaded
if isempty(equations)
Expand Down
Binary file modified readme/RAVEN_structure_fields.xlsx
Binary file not shown.

2 comments on commit 6f29d82

@edkerk
Copy link
Member

@edkerk edkerk commented on 6f29d82 Apr 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simas232 metaCycRxns.mat in this commit is faulty, it only includes a cell array called TRANSPORT

@simas232
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edkerk, thank you for noticing this. Such issue is addressed in #71.

Please sign in to comment.