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 (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)

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 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 end
0099 
0100 %Remove unused reactions
0101 if removeUnusedRxns==true
0102     %Get unused reactions
0103     [~, a]=find(reducedModel.S);
0104     rxnsToRemove=1:numel(reducedModel.rxns);
0105     rxnsToRemove(a)=[];
0106     reducedModel=removeReactions(reducedModel,rxnsToRemove,false,removeUnusedGenes);
0107 end
0108 
0109 %Remove unused compartments
0110 if removeUnusedComps==true
0111     oldComps=reducedModel.comps;
0112     I=ismember(1:numel(oldComps),reducedModel.metComps);
0113     if ~all(I)
0114         reducedModel.comps(~I)=[];
0115         reducedModel.compNames(~I)=[];
0116         if isfield(reducedModel,'compOutside')
0117             reducedModel.compOutside(~I)=[];
0118         end
0119         if isfield(reducedModel,'compMiriams')
0120             reducedModel.compMiriams(~I)=[];
0121         end
0122         [~, J]=ismember(oldComps(reducedModel.metComps),reducedModel.comps);
0123         reducedModel.metComps=J;
0124     end
0125 end
0126 end

Generated by m2html © 2005