changeRxnMets Change metabolites in a specified reaction, or randomly chosen reactions. [model ModifiedRxns] = changeRxnMets(model,Mets2change,NewMets,Rxn,NewStoich) INPUTS model COBRA model structure Mets2change Cell array of metabolites to change NewMets Cell array of replacement metabolites (must be in order of those that will be replaced Rxn reaction to change (string) or cell array, or if a number is put here, that number of reactions (with Mets2change) will be randomly chosen and the metabolites will be swapped OPTIONAL INPUT NewStoich Stoichiometry of new metabs (conserved from old mets by default). If multiple reactions are being changed, this must be a mets x rxns matrix, e.g. for 2 new reactions: Rxn = {'r1','r2'} r1: 2 A + 3 B -> 1 C r2: 4 A + 3 B -> 3 C where A and C are the new metabolites, NewMets = {'A', 'C'} NewStoich = [ 2 4; 1 3] OUTPUTS model COBRA model structure with changed reaction ModifiedRxns Rxns which were modified Nathan Lewis (Apr 24, 2009)
0001 function [model ModifiedRxns] = changeRxnMets(model,Mets2change,NewMets,Rxn,NewStoich) 0002 %changeRxnMets Change metabolites in a specified reaction, or 0003 % randomly chosen reactions. 0004 % 0005 % [model ModifiedRxns] = changeRxnMets(model,Mets2change,NewMets,Rxn,NewStoich) 0006 % 0007 %INPUTS 0008 % model COBRA model structure 0009 % Mets2change Cell array of metabolites to change 0010 % NewMets Cell array of replacement metabolites (must be in 0011 % order of those that will be replaced 0012 % Rxn reaction to change (string) or cell array, or if a number is put 0013 % here, that number of reactions (with Mets2change) will 0014 % be randomly chosen and the metabolites will be swapped 0015 % 0016 %OPTIONAL INPUT 0017 % NewStoich Stoichiometry of new metabs (conserved from old mets by default). 0018 % If multiple reactions are being changed, this must be 0019 % a mets x rxns matrix, 0020 % e.g. for 2 new reactions: Rxn = {'r1','r2'} 0021 % r1: 2 A + 3 B -> 1 C 0022 % r2: 4 A + 3 B -> 3 C 0023 % where A and C are the new metabolites, 0024 % NewMets = {'A', 'C'} 0025 % NewStoich = [ 2 4; 1 3] 0026 % 0027 %OUTPUTS 0028 % model COBRA model structure with changed reaction 0029 % ModifiedRxns Rxns which were modified 0030 % 0031 % Nathan Lewis (Apr 24, 2009) 0032 0033 if nargin ==4 0034 NewStoich = []; 0035 end 0036 0037 %%% make sure metabolites are in the model 0038 OldMetInd = findMetIDs(model,Mets2change); 0039 NewMetInd = findMetIDs(model,NewMets); 0040 if min(OldMetInd) == 0 || min(NewMetInd) == 0 0041 error('A metabolite wasn''t found in your model!') 0042 end 0043 if ~all(isnumeric(Rxn)) 0044 %%% make sure rxns are in the model 0045 RxnsInd = findRxnIDs(model,Rxn); 0046 if min(RxnsInd == 0) 0047 error('A reaction wasn''t found in your model!') 0048 end 0049 model = changeMets(model,OldMetInd,NewMetInd,RxnsInd,NewStoich); 0050 ModifiedRxns = model.rxns(RxnsInd); 0051 else 0052 %%% find all reactions with the old mets, and choose the specified number of rxns 0053 RxnsInd = 1:length(model.rxns); 0054 tempS = full(model.S); 0055 for i = 1:length(OldMetInd) 0056 RxnsInd = intersect(find(tempS(OldMetInd(i),:)),RxnsInd); 0057 end 0058 if length(RxnsInd)<Rxn 0059 warning('Fewer reactions have your metabolites than the number you wanted to randomly choose!') 0060 RxnsToSwitch = RxnsInd(ceil(rand(length(RxnsInd),1))); 0061 Rxn = length(RxnsToSwitch); 0062 else 0063 %%% chose the reactions to randomize 0064 RxnsToSwitch = []; 0065 Rxns2Exclude = findRxnIDs(model,{'DM_SC_PRECUSOR'}); 0066 for r=1:length(Rxns2Exclude) 0067 tmp = find(RxnsInd==Rxns2Exclude(r)); 0068 if ~isempty(tmp) 0069 RxnsInd(tmp) = []; 0070 end 0071 end 0072 while length(unique(RxnsToSwitch))<Rxn 0073 0074 RxnsToSwitch = RxnsInd(ceil(rand(length(RxnsInd),1)*length(RxnsInd))); 0075 RxnsToSwitch = RxnsToSwitch(1:Rxn); 0076 end 0077 end 0078 0079 model = changeMets(model,OldMetInd,NewMetInd,RxnsToSwitch,NewStoich); 0080 ModifiedRxns = model.rxns(RxnsToSwitch); 0081 0082 end 0083 end 0084 function model = changeMets(model,OldMetInd,NewMetInd,RxnsInd,NewStoich) 0085 if isempty(NewStoich) 0086 NewStoich = model.S(OldMetInd,RxnsInd); 0087 end 0088 for i = 1:length(RxnsInd) 0089 model.S(OldMetInd,RxnsInd(i))=0; 0090 model.S(NewMetInd,RxnsInd(i))=NewStoich(:,i); 0091 end 0092 end