Home > RAVEN > removeMets.m

removeMets

PURPOSE ^

removeMets

SYNOPSIS ^

function reducedModel=removeMets(model,metsToRemove,isNames,removeUnusedRxns,removeUnusedGenes,removeUnusedComps)

DESCRIPTION ^

 removeMets
   Deletes a set of metabolites from a model

   model             a model structure
   metsToRemove      either a cell array of metabolite IDs, a logical vector 
                     with the same number of elements as metabolites in the model,
                     of a vector of indexes to remove
   isNames           true if the supplied mets represent metabolite names
                     (as opposed to IDs). This is a way to delete
                     metabolites in several compartments at once without
                     knowing the exact IDs. This only works if metsToRemove
                     is a cell array (opt, default false)
   removeUnusedRxns  remove reactions that are no longer in use (opt,
                     default false)
   removeUnusedGenes remove genes that are no longer in use (opt,
                     default false)
   removeUnusedComps remove compartments that are no longer in use (opt,
                     default false)

   reducedModel      an updated model structure

   Usage: reducedModel=removeMets(model,metsToRemove,isNames,...
           removeUnusedRxns,removeUnusedGenes,removeUnusedComps)

   Rasmus Agren, 2013-07-16

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function reducedModel=removeMets(model,metsToRemove,isNames,removeUnusedRxns,removeUnusedGenes,removeUnusedComps)
0002 % removeMets
0003 %   Deletes a set of metabolites from a model
0004 %
0005 %   model             a model structure
0006 %   metsToRemove      either a cell array of metabolite IDs, a logical vector
0007 %                     with the same number of elements as metabolites in the model,
0008 %                     of a vector of indexes to remove
0009 %   isNames           true if the supplied mets represent metabolite names
0010 %                     (as opposed to IDs). This is a way to delete
0011 %                     metabolites in several compartments at once without
0012 %                     knowing the exact IDs. This only works if metsToRemove
0013 %                     is a cell array (opt, default false)
0014 %   removeUnusedRxns  remove reactions that are no longer in use (opt,
0015 %                     default false)
0016 %   removeUnusedGenes remove genes that are no longer in use (opt,
0017 %                     default false)
0018 %   removeUnusedComps remove compartments that are no longer in use (opt,
0019 %                     default false)
0020 %
0021 %   reducedModel      an updated model structure
0022 %
0023 %   Usage: reducedModel=removeMets(model,metsToRemove,isNames,...
0024 %           removeUnusedRxns,removeUnusedGenes,removeUnusedComps)
0025 %
0026 %   Rasmus Agren, 2013-07-16
0027 %
0028 
0029 if ischar(metsToRemove)
0030     metsToRemove={metsToRemove};
0031 end
0032 
0033 if nargin<3
0034     isNames=false;
0035 end
0036 
0037 if nargin<4
0038     removeUnusedRxns=false;
0039 end
0040 
0041 if nargin<5
0042     removeUnusedGenes=false;
0043 end
0044 
0045 if nargin<6
0046     removeUnusedComps=false;
0047 end
0048 
0049 if isNames==true
0050    %Check that metsToRemove is a cell array
0051    if iscellstr(metsToRemove)==false
0052        if ischar(metsToRemove)
0053             metsToRemove={metsToRemove};
0054        else
0055             throw(MException('','Must supply a cell array of strings if isNames=true'));
0056        end
0057    end 
0058 end
0059 
0060 reducedModel=model;
0061 
0062 if isNames==false
0063     indexesToDelete=getIndexes(model,metsToRemove,'mets');
0064 else
0065     indexesToDelete=[];
0066     for i=1:numel(metsToRemove)
0067        indexesToDelete=[indexesToDelete;find(strcmp(metsToRemove(i),model.metNames))]; 
0068     end
0069 end
0070 
0071 %Remove metabolites
0072 if ~isempty(indexesToDelete)    
0073     reducedModel.mets(indexesToDelete)=[];
0074     reducedModel.S(indexesToDelete,:)=[];
0075     if isfield(reducedModel,'b')
0076         reducedModel.b(indexesToDelete,:)=[];
0077     end
0078     if isfield(reducedModel,'metNames')
0079         reducedModel.metNames(indexesToDelete)=[];
0080     end
0081     if isfield(reducedModel,'metComps')
0082         reducedModel.metComps(indexesToDelete)=[];
0083     end
0084     if isfield(reducedModel,'inchis')
0085         reducedModel.inchis(indexesToDelete)=[];
0086     end
0087     if isfield(reducedModel,'metFormulas')
0088         reducedModel.metFormulas(indexesToDelete)=[];
0089     end
0090     if isfield(reducedModel,'metMiriams')
0091         reducedModel.metMiriams(indexesToDelete)=[];
0092     end
0093     if isfield(reducedModel,'unconstrained')
0094         reducedModel.unconstrained(indexesToDelete)=[];
0095     end
0096     if isfield(reducedModel,'metFrom')
0097         reducedModel.metFrom(indexesToDelete)=[];
0098     end
0099 end
0100 
0101 %Remove unused reactions
0102 if removeUnusedRxns==true
0103     %Get unused reactions
0104     [crap a crap]=find(reducedModel.S);
0105     rxnsToRemove=1:numel(reducedModel.rxns);
0106     rxnsToRemove(a)=[];
0107     reducedModel=removeRxns(reducedModel,rxnsToRemove,false,removeUnusedGenes);
0108 end
0109 
0110 %Remove unused compartments
0111 if removeUnusedComps==true
0112     oldComps=reducedModel.comps;
0113     I=ismember(1:numel(oldComps),reducedModel.metComps);
0114     if ~all(I)
0115         reducedModel.comps(~I)=[];
0116         reducedModel.compNames(~I)=[];
0117         if isfield(reducedModel,'compOutside')
0118             reducedModel.compOutside(~I)=[];
0119         end
0120         if isfield(reducedModel,'compMiriams')
0121             reducedModel.compMiriams(~I)=[];
0122         end
0123         [crap J]=ismember(oldComps(reducedModel.metComps),reducedModel.comps);
0124         reducedModel.metComps=J;
0125     end
0126 end
0127 end

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