keepCompartment

PURPOSE ^

This function removes reactions in all compartments except those

SYNOPSIS ^

function model = keepCompartment(model, compartments)

DESCRIPTION ^

 This function removes reactions in all compartments except those
 specified by the cell array "compartments"
 
INPUTS
 model                     COBRA model structure
 compartments              cell array of strings (e.g., to discard all
                           reactions except those in the mitochondria and 
                           cytosol, compartments = {'[m]','[c]'};

OUTPUT
 model                     COBRA model with reactions in the specified
                           compartmetns
 
 Nathan Lewis
 June 8, 2008

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function model = keepCompartment(model, compartments)
0002 % This function removes reactions in all compartments except those
0003 % specified by the cell array "compartments"
0004 %
0005 %INPUTS
0006 % model                     COBRA model structure
0007 % compartments              cell array of strings (e.g., to discard all
0008 %                           reactions except those in the mitochondria and
0009 %                           cytosol, compartments = {'[m]','[c]'};
0010 %
0011 %OUTPUT
0012 % model                     COBRA model with reactions in the specified
0013 %                           compartmetns
0014 %
0015 % Nathan Lewis
0016 % June 8, 2008
0017 
0018 % compartments is a cell array list of compartments to keep (e.g. {'[e]','[c]','[m]'})
0019 compartments = regexprep(compartments, '\[','\\\[');
0020 compartments = regexprep(compartments, '\]','\\\]');
0021 % make a list of metabolites which are in the desired compartment
0022 mets2keep = zeros(size(model.mets));
0023 for i=1:max(size(compartments))
0024     a(:,i)=regexpi(model.mets,compartments{i});
0025     for j=1:max(size(a(:,i)))
0026         if not(isempty(a{j,i}))
0027             mets2keep(j,1)=1;
0028         end
0029     end
0030 end
0031 % make a list of rxns to remove
0032 k=1;rxns2remove={};
0033 for j=max(size(model.rxns)):-1:1
0034     for i=max(size(mets2keep)):-1:1
0035         if model.S(i,j) ~= 0 && mets2keep(i) == 0
0036             rxns2remove{k}=model.rxns{j};k=k+1;
0037             ID = findRxnIDs(model,model.rxns{j});
0038             printRxnFormula(model,model.rxns{j});
0039             hi=1;
0040         end
0041     end
0042 end
0043 % remove rxns
0044 hi = 1;
0045 if ~isempty(rxns2remove)
0046     for i=1:max(size(rxns2remove))
0047         model = removeRxns(model,rxns2remove{i});
0048     end
0049 else display('No Compartments Removed')
0050 end
0051 end

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003