Home > RAVEN > expandModel.m

expandModel

PURPOSE ^

expandModel

SYNOPSIS ^

function newModel=expandModel(model)

DESCRIPTION ^

 expandModel
   Expands a model which uses several gene associations for one reaction.
   Each such reaction is split into several reactions, each under the control
   of only one gene.

   model     A model structure

   newModel  A model structure with separate reactions for iso-enzymes

    The reaction ids are renamed according to id_EXP_1, id_EXP_2..

   NOTE: As it is now this code might not work for advanced grRules strings
   that involve nested expressions of 'and' and 'or'

   Usage: newModel=expandModel(model)

   Rasmus Agren, 2012-02-12

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function newModel=expandModel(model)
0002 % expandModel
0003 %   Expands a model which uses several gene associations for one reaction.
0004 %   Each such reaction is split into several reactions, each under the control
0005 %   of only one gene.
0006 %
0007 %   model     A model structure
0008 %
0009 %   newModel  A model structure with separate reactions for iso-enzymes
0010 %
0011 %    The reaction ids are renamed according to id_EXP_1, id_EXP_2..
0012 %
0013 %   NOTE: As it is now this code might not work for advanced grRules strings
0014 %   that involve nested expressions of 'and' and 'or'
0015 %
0016 %   Usage: newModel=expandModel(model)
0017 %
0018 %   Rasmus Agren, 2012-02-12
0019 %
0020 
0021 %Start by checking which reactions could be expanded
0022 rxnsToExpand=false(numel(model.rxns),1);        
0023 
0024 for i=1:numel(model.rxns)
0025     if findstr(model.grRules{i},' or ');
0026         rxnsToExpand(i)=true;
0027     end
0028 end
0029 
0030 rxnsToExpand=find(rxnsToExpand);
0031 
0032 if any(rxnsToExpand)
0033     %Loop throught those reactions and expand them
0034     for i=1:numel(rxnsToExpand)
0035         %Check that it doesn't contain nested 'and' and 'or' relations and
0036         %print a warning if it does
0037         if findstr(model.grRules{rxnsToExpand(i)},' and ')
0038             fprintf(['WARNING: Reaction ' model.rxns{rxnsToExpand(i)} ' contains nested and/or-relations. Large risk of errors\n']);
0039         end
0040         
0041         %Get rid of all '(' and ')' since I'm not looking at complex stuff
0042         %anyways
0043         geneString=model.grRules{rxnsToExpand(i)};
0044         geneString=strrep(geneString,'(','');
0045         geneString=strrep(geneString,')','');
0046         geneString=strrep(geneString,' or ',';');
0047         
0048         %Split the string into gene names
0049         [crap crap crap crap crap crap geneNames]=regexp(geneString,';');
0050         
0051         %Update the reaction to only use the first gene
0052         model.grRules{rxnsToExpand(i)}=['(' geneNames{1} ')'];
0053         %Find the gene in the gene list
0054         index=strmatch(geneNames(1),model.genes,'exact');
0055         model.rxnGeneMat(rxnsToExpand(i),:)=0;
0056         model.rxnGeneMat(rxnsToExpand(i),index)=1;
0057         
0058         %Insert the reactions at the end of the model and without
0059         %allocating space. This is not nice, but ok for now
0060         for j=2:numel(geneNames)
0061             model.rxns=[model.rxns;[model.rxns{rxnsToExpand(i)} '_EXP_' num2str(j)]];
0062             model.rxnNames=[model.rxnNames;model.rxnNames(rxnsToExpand(i))];
0063             model.lb=[model.lb;model.lb(rxnsToExpand(i))];
0064             model.ub=[model.ub;model.ub(rxnsToExpand(i))];
0065             model.rev=[model.rev;model.rev(rxnsToExpand(i))];
0066             model.c=[model.c;model.c(rxnsToExpand(i))];
0067             model.S=[model.S model.S(:,rxnsToExpand(i))];
0068             model.grRules=[model.grRules;['(' geneNames{j} ')']];
0069             
0070             index=strmatch(geneNames(j),model.genes,'exact');
0071             pad=sparse(1,numel(model.genes));
0072             pad(index)=1;
0073             model.rxnGeneMat=[model.rxnGeneMat;pad];
0074             
0075             if isfield(model,'subSystems')
0076                 model.subSystems=[model.subSystems;model.subSystems(rxnsToExpand(i))];
0077             end
0078             if isfield(model,'eccodes')
0079                 model.eccodes=[model.eccodes;model.eccodes(rxnsToExpand(i))];
0080             end
0081             if isfield(model,'equations')
0082                 model.equations=[model.equations;model.equations(rxnsToExpand(i))];
0083             end
0084             if isfield(model,'rxnMiriams')
0085                 model.rxnMiriams=[model.rxnMiriams;model.rxnMiriams(rxnsToExpand(i))];
0086             end
0087             if isfield(model,'rxnFrom')
0088                 model.rxnFrom=[model.rxnFrom;model.rxnFrom(rxnsToExpand(i))];
0089             end
0090         end
0091     end
0092     newModel=model;
0093 else
0094     %There are no reactions to expand, return the model as is
0095     newModel=model;
0096 end
0097 end

Generated on Tue 16-Jul-2013 21:50:02 by m2html © 2005