Home > core > 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 (optional, default false)
   removeUnusedRxns  remove reactions that are no longer in use (optional,
                     default false)
   removeUnusedGenes remove genes that are no longer in use (optional,
                     default false)
   removeUnusedComps remove compartments that are no longer in use (optional,
                     default false)

   reducedModel      an updated model structure

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

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 (optional, default false)
0014 %   removeUnusedRxns  remove reactions that are no longer in use (optional,
0015 %                     default false)
0016 %   removeUnusedGenes remove genes that are no longer in use (optional,
0017 %                     default false)
0018 %   removeUnusedComps remove compartments that are no longer in use (optional,
0019 %                     default false)
0020 %
0021 %   reducedModel      an updated model structure
0022 %
0023 % Usage: reducedModel=removeMets(model,metsToRemove,isNames,...
0024 %           removeUnusedRxns,removeUnusedGenes,removeUnusedComps)
0025 if ~islogical(metsToRemove) && ~isnumeric(metsToRemove)
0026     metsToRemove=convertCharArray(metsToRemove);
0027 end
0028 
0029 if nargin<3
0030     isNames=false;
0031 end
0032 
0033 if nargin<4
0034     removeUnusedRxns=false;
0035 end
0036 
0037 if nargin<5
0038     removeUnusedGenes=false;
0039 end
0040 
0041 if nargin<6
0042     removeUnusedComps=false;
0043 end
0044 
0045 %Check that metsToRemove is a cell array
0046 if isNames==true && ~iscell(metsToRemove)
0047     error('Must supply a cell array of strings if isNames=true');
0048 end
0049 
0050 reducedModel=model;
0051 
0052 if isNames==false
0053     indexesToDelete=getIndexes(model,metsToRemove,'mets');
0054 else
0055     indexesToDelete=[];
0056     for i=1:numel(metsToRemove)
0057         indexesToDelete=[indexesToDelete;find(strcmp(metsToRemove(i),model.metNames))];
0058     end
0059 end
0060 
0061 %Remove metabolites
0062 if ~isempty(indexesToDelete)
0063     reducedModel.mets(indexesToDelete)=[];
0064     reducedModel.S(indexesToDelete,:)=[];
0065     if isfield(reducedModel,'b')
0066         reducedModel.b(indexesToDelete,:)=[];
0067     end
0068     if isfield(reducedModel,'metNames')
0069         reducedModel.metNames(indexesToDelete)=[];
0070     end
0071     if isfield(reducedModel,'metComps')
0072         reducedModel.metComps(indexesToDelete)=[];
0073     end
0074     if isfield(reducedModel,'inchis')
0075         reducedModel.inchis(indexesToDelete)=[];
0076     end
0077     if isfield(reducedModel,'metSmiles')
0078         reducedModel.metSmiles(indexesToDelete)=[];
0079     end
0080     if isfield(reducedModel,'metFormulas')
0081         reducedModel.metFormulas(indexesToDelete)=[];
0082     end
0083     if isfield(reducedModel,'metMiriams')
0084         reducedModel.metMiriams(indexesToDelete)=[];
0085     end
0086     if isfield(reducedModel,'unconstrained')
0087         reducedModel.unconstrained(indexesToDelete)=[];
0088     end
0089     if isfield(reducedModel,'metFrom')
0090         reducedModel.metFrom(indexesToDelete)=[];
0091     end
0092     if isfield(reducedModel,'metCharges')
0093         reducedModel.metCharges(indexesToDelete)=[];
0094     end
0095     if isfield(reducedModel,'metDeltaG')
0096         reducedModel.metDeltaG(indexesToDelete)=[];
0097     end
0098     if isfield(reducedModel,'metNotes')
0099         reducedModel.metNotes(indexesToDelete)=[];
0100     end    
0101 end
0102 
0103 %Remove unused reactions
0104 if removeUnusedRxns==true
0105     %Get unused reactions
0106     [~, a]=find(reducedModel.S);
0107     rxnsToRemove=1:numel(reducedModel.rxns);
0108     rxnsToRemove(a)=[];
0109     reducedModel=removeReactions(reducedModel,rxnsToRemove,false,removeUnusedGenes);
0110 end
0111 
0112 %Remove unused compartments
0113 if removeUnusedComps==true
0114     oldComps=reducedModel.comps;
0115     I=ismember(1:numel(oldComps),reducedModel.metComps);
0116     if ~all(I)
0117         reducedModel.comps(~I)=[];
0118         reducedModel.compNames(~I)=[];
0119         if isfield(reducedModel,'compOutside')
0120             reducedModel.compOutside(~I)=[];
0121         end
0122         if isfield(reducedModel,'compMiriams')
0123             reducedModel.compMiriams(~I)=[];
0124         end
0125         [~, J]=ismember(oldComps(reducedModel.metComps),reducedModel.comps);
0126         reducedModel.metComps=J;
0127     end
0128 end
0129 end

Generated by m2html © 2005