copyToComps Copies reactions to new compartment(s) model a model structure toComps cell array of compartment ids. If there is no match to model.comps then it is added as a new compartment (see below for details) rxns either a cell array of reaction IDs, a logical vector with the same number of elements as reactions in the model, or a vector of indexes to remove (opt, default model.rxns) deleteOriginal true if the original reactions should be removed (making it move the reactions instead) (opt, default false) compNames cell array of compartment names. This is used if new compartments should be added (opt, default toComps) compOutside cell array of the id (as in comps) for the compartment surrounding each of the compartments. This is used if new compartments should be added (opt, default all {''}) model an updated model structure NOTE: New reactions and metabolites will be named as "id_toComps(i)". Usage: model=copyToComps(model,toComps,rxns,deleteOriginal,compNames,compOutside) Rasmus Agren, 2013-02-07
0001 function model=copyToComps(model,toComps,rxns,deleteOriginal,compNames,compOutside) 0002 % copyToComps 0003 % Copies reactions to new compartment(s) 0004 % 0005 % model a model structure 0006 % toComps cell array of compartment ids. If there is no match 0007 % to model.comps then it is added as a new compartment 0008 % (see below for details) 0009 % rxns either a cell array of reaction IDs, a logical vector 0010 % with the same number of elements as reactions in the model, 0011 % or a vector of indexes to remove (opt, default 0012 % model.rxns) 0013 % deleteOriginal true if the original reactions should be removed 0014 % (making it move the reactions instead) (opt, default 0015 % false) 0016 % compNames cell array of compartment names. This is used if new 0017 % compartments should be added (opt, default toComps) 0018 % compOutside cell array of the id (as in comps) for the compartment 0019 % surrounding each of the compartments. This is used if 0020 % new compartments should be added (opt, default all {''}) 0021 % 0022 % model an updated model structure 0023 % 0024 % NOTE: New reactions and metabolites will be named as "id_toComps(i)". 0025 % 0026 % Usage: model=copyToComps(model,toComps,rxns,deleteOriginal,compNames,compOutside) 0027 % 0028 % Rasmus Agren, 2013-02-07 0029 % 0030 0031 if nargin<3 0032 rxns=model.rxns; 0033 end 0034 if nargin<4 0035 deleteOriginal=false; 0036 end 0037 if nargin<5 0038 compNames=toComps; 0039 end 0040 if nargin<6 0041 compOutside=cell(numel(toComps),1); 0042 compOutside(:)={''}; 0043 end 0044 0045 rxns=getIndexes(model,rxns,'rxns'); 0046 0047 for i=1:numel(toComps) 0048 %Check if the compartment exists, otherwise add it 0049 [I J]=ismember(toComps(i),model.comps); 0050 if I==false 0051 model.comps=[model.comps;toComps(i)]; 0052 model.compNames=[model.compNames;compNames(i)]; 0053 if isfield(model,'compOutside') 0054 model.compOutside=[model.compOutside;compOutside(i)]; 0055 end 0056 J=numel(model.comps); 0057 end 0058 %Copy the reactions by making a model structure with only them, then 0059 %change the localization, and finally merge with the original model 0060 modelToAdd=model; 0061 modelToAdd=removeRxns(modelToAdd,setdiff(1:numel(model.rxns),rxns),true,true); 0062 modelToAdd.rxns=strcat(modelToAdd.rxns,'_',toComps(i)); 0063 modelToAdd.mets=strcat(modelToAdd.mets,'_',toComps(i)); 0064 modelToAdd.comps=modelToAdd.comps(J); 0065 modelToAdd.compNames=modelToAdd.compNames(J); 0066 if isfield(modelToAdd,'compOutside') 0067 modelToAdd.compOutside=modelToAdd.compOutside(J); 0068 end 0069 modelToAdd.metComps=ones(numel(modelToAdd.mets),1); 0070 0071 %Merge the models 0072 model=mergeModels({model;modelToAdd}); 0073 end 0074 0075 if deleteOriginal==true 0076 model=removeRxns(model,rxns,true,true,true); %Also delete unused compartments 0077 end 0078 end