Home > RAVEN > addTransport.m

addTransport

PURPOSE ^

addTransport

SYNOPSIS ^

function [model addedRxns]=addTransport(model,fromComp,toComps,metNames,isRev,onlyToExisting)

DESCRIPTION ^

 addTransport
   Adds transport reactions between compartments

   model           a model structure
   fromComp        the id of the compartment to transport from (should
                   match model.comps)
   toComps         a cell array of compartment names to transport to (should
                   match model.comps)
   metNames        the metabolite names to add transport for (opt, all
                   metabolites in fromComp)
   isRev           true if the transport reactions should be reversible
                   (opt, default true)
   onlyToExisting  true if transport of a metabolite should only be added
                   if it already exists in toComp. If false, then new metabolites
                   are added with addMets first (opt, default true)

   This is a faster version than addRxns when adding transport reactions.
   New reactions are named "T_fromComp_to_toComp_metID in fromComp".

   Usage: [model addedRxns]=addTransport(model,fromComp,toComps,metNames,...
           isRev,onlyToExisting)

   Rasmus Agren, 2013-08-01

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [model addedRxns]=addTransport(model,fromComp,toComps,metNames,isRev,onlyToExisting)
0002 % addTransport
0003 %   Adds transport reactions between compartments
0004 %
0005 %   model           a model structure
0006 %   fromComp        the id of the compartment to transport from (should
0007 %                   match model.comps)
0008 %   toComps         a cell array of compartment names to transport to (should
0009 %                   match model.comps)
0010 %   metNames        the metabolite names to add transport for (opt, all
0011 %                   metabolites in fromComp)
0012 %   isRev           true if the transport reactions should be reversible
0013 %                   (opt, default true)
0014 %   onlyToExisting  true if transport of a metabolite should only be added
0015 %                   if it already exists in toComp. If false, then new metabolites
0016 %                   are added with addMets first (opt, default true)
0017 %
0018 %   This is a faster version than addRxns when adding transport reactions.
0019 %   New reactions are named "T_fromComp_to_toComp_metID in fromComp".
0020 %
0021 %   Usage: [model addedRxns]=addTransport(model,fromComp,toComps,metNames,...
0022 %           isRev,onlyToExisting)
0023 %
0024 %   Rasmus Agren, 2013-08-01
0025 %
0026 
0027 if iscell(fromComp)
0028     fromComp=fromComp{1};
0029 end
0030 [I fromID]=ismember(model.comps,fromComp);
0031 fromID=find(fromID);
0032 if sum(I)~=1
0033     dispEM('fromComps must have exactly one match in model.comps');
0034 end
0035 if ischar(toComps)
0036     toComps={toComps};
0037 end
0038 [I toIDs]=ismember(toComps,model.comps);
0039 if ~all(I)
0040     dispEM('All compartments in toComps must have a match in model.comps');
0041 end
0042 if nargin<4
0043     %Find all metabolites in fromComp
0044     metNames=model.metNames(model.metComps==fromID);
0045 end
0046 
0047 %If an empty set was given
0048 if isempty(metNames)
0049     %Find all metabolites in fromComp
0050     metNames=model.metNames(ismember(model.metComps,model.comps(fromID)));
0051 end
0052 
0053 if nargin<5
0054     isRev=true;
0055 end
0056 if nargin<6
0057     onlyToExisting=true;
0058 end
0059 
0060 %Check that the names are unique
0061 if numel(unique(metNames))~=numel(metNames)
0062     dispEM('Not all metabolite names are unique');
0063 end
0064 
0065 %Get the indexes of the mets in fromComp
0066 I=find(model.metComps==fromID);
0067 [J K]=ismember(metNames,model.metNames(I));
0068 if ~all(J)
0069     dispEM('Not all metabolites in metNames exist in fromComp');
0070 end
0071 fromMets=I(K); %These are the ids of the metabolites to transport. The order corresponds to metNames
0072 
0073 %Loop through and add for each compartment in toComps
0074 for i=1:numel(toComps)
0075     fromMetsInComp=fromMets; %If onlyToExisting==true then not all mets are transported to each compartment
0076     %Get the indexes of the mets in the compartment
0077     I=find(model.metComps==toIDs(i));
0078     [J K]=ismember(metNames,model.metNames(I));
0079     if onlyToExisting==true || all(J)
0080         toMets=I(K(J)); %Only look at the existing ones
0081         fromMetsInComp=fromMetsInComp(J);
0082     else
0083         %This is if not all metabolites exist in the target compartment,
0084         %and they should be added
0085         metsToAdd.metNames=metNames(J==0);
0086         metsToAdd.compartments=toComps{i};
0087         model=addMets(model,metsToAdd);
0088         
0089         %Redo the mapping when all mets are there. A bit lazy, but it's
0090         %fast anyways
0091         I=find(model.metComps==toIDs(i));
0092         [crap K]=ismember(metNames,model.metNames(I));
0093         toMets=I(K); %All are guaranteed to be found now
0094     end
0095     
0096     %Construct the S matrix
0097     nRxns=numel(fromMetsInComp);
0098     newS=zeros(numel(model.mets),nRxns);
0099     newS(sub2ind(size(newS),fromMetsInComp(:),(1:nRxns)'))=-1;
0100     newS(sub2ind(size(newS),toMets(:),(1:nRxns)'))=1;
0101     
0102     %Add the reactions
0103     model.S=[model.S sparse(newS)];
0104     if isRev==true
0105         model.lb=[model.lb;ones(nRxns,1)*-inf];
0106         model.rev=[model.rev;ones(nRxns,1)];
0107     else
0108         model.lb=[model.lb;zeros(nRxns,1)];
0109         model.rev=[model.rev;zeros(nRxns,1)];
0110     end
0111     model.ub=[model.ub;ones(nRxns,1)*inf];
0112     model.c=[model.c;zeros(nRxns,1)];
0113     
0114     %Add annotation
0115     filler=cell(nRxns,1);
0116     filler(:)={''};
0117     addedRxns=strcat({['T_' fromComp '_to_' toComps{i} '_']},model.mets(fromMetsInComp));
0118     model.rxns=[model.rxns;addedRxns];
0119     model.rxnNames=[model.rxnNames;addedRxns];
0120 
0121     if isfield(model,'eccodes')
0122         model.eccodes=[model.eccodes;filler];
0123     end
0124     if isfield(model,'subSystems')
0125         ssFiller=filler;
0126         if isRev==1
0127             ssFiller(:)={['Transport between ' fromComp ' and ' toComps{i}]};
0128         else
0129             ssFiller(:)={['Transport from ' fromComp ' to ' toComps{i}]};
0130         end
0131         model.subSystems=[model.subSystems;ssFiller];
0132     end
0133     if isfield(model,'grRules')
0134         model.grRules=[model.grRules;filler];
0135     end
0136     if isfield(model,'rxnFrom')
0137         model.rxnFrom=[model.rxnFrom;filler];
0138     end
0139     if isfield(model,'rxnMiriams')
0140         model.rxnMiriams=[model.rxnFrom;cell(nRxns,1)];
0141     end
0142     if isfield(model,'rxnComps')
0143         model.rxnComps=[model.rxnComps;ones(nRxns,1)];
0144         fprintf('NOTE: The added transport reactions will be added to the first compartment\n');
0145     end
0146     if isfield(model,'rxnGeneMat')
0147         model.rxnGeneMat=[model.rxnGeneMat;sparse(nRxns,numel(model.genes))];
0148     end
0149 end
0150 end

Generated on Mon 06-Jan-2014 14:58:12 by m2html © 2005