


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 (optional, default
model.rxns)
deleteOriginal true if the original reactions should be removed
(making it move the reactions instead) (optional, default
false)
compNames cell array of compartment names. This is used if new
compartments should be added (optional, 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 (optional, 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)

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 (optional, default 0012 % model.rxns) 0013 % deleteOriginal true if the original reactions should be removed 0014 % (making it move the reactions instead) (optional, default 0015 % false) 0016 % compNames cell array of compartment names. This is used if new 0017 % compartments should be added (optional, 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 (optional, 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 arguments 0029 model (1,1) struct 0030 toComps {emptyOrTextOrCellOfText} 0031 rxns = model.rxns 0032 deleteOriginal {emptyOrLogicalScalar} = false 0033 compNames {emptyOrTextOrCellOfText} = toComps 0034 compOutside {emptyOrTextOrCellOfText} = ''; 0035 end 0036 0037 if nargin >= 3 && ~islogical(rxns) && ~isnumeric(rxns) 0038 rxns = convertCharArray(rxns); 0039 end 0040 if nargin >= 5 0041 compNames=convertCharArray(compNames); 0042 end 0043 if nargin >= 6 0044 compOutside=convertCharArray(compOutside); 0045 if length(compOutside) ~= length(compNames) 0046 error('compOutside and compNames should be of equal size.'); 0047 end 0048 end 0049 0050 originalID=model.id; 0051 originalName=model.name; 0052 0053 rxns=getIndexes(model,rxns,'rxns'); 0054 0055 for i=1:numel(toComps) 0056 %Check if the compartment exists, otherwise add it 0057 [I,J]=ismember(toComps(i),model.comps); 0058 if I==false 0059 model.comps=[model.comps;toComps(i)]; 0060 model.compNames=[model.compNames;compNames(i)]; 0061 if isfield(model,'compOutside') 0062 model.compOutside=[model.compOutside;compOutside(i)]; 0063 end 0064 if isfield(model,'compMiriams') 0065 model.compMiriams=[model.compMiriams;cell(1,1)]; 0066 end 0067 J=numel(model.comps); 0068 end 0069 %Copy the reactions by making a model structure with only them, then 0070 %change the localization, and finally merge with the original model 0071 modelToAdd=model; 0072 modelToAdd=removeReactions(modelToAdd,setdiff(1:numel(model.rxns),rxns),true,true); 0073 modelToAdd.rxns=strcat(modelToAdd.rxns,'_',toComps(i)); 0074 modelToAdd.mets=strcat(modelToAdd.mets,'_',toComps(i)); 0075 modelToAdd.comps=modelToAdd.comps(J); 0076 modelToAdd.compNames=modelToAdd.compNames(J); 0077 if isfield(modelToAdd,'compOutside') 0078 modelToAdd.compOutside=modelToAdd.compOutside(J); 0079 end 0080 if isfield(modelToAdd,'compMiriams') 0081 modelToAdd.compMiriams=modelToAdd.compMiriams(J); 0082 end 0083 modelToAdd.metComps=ones(numel(modelToAdd.mets),1); 0084 if isfield(modelToAdd,'metFrom') 0085 modelToAdd = rmfield(modelToAdd,'metFrom'); 0086 end 0087 if isfield(modelToAdd,'rxnFrom') 0088 modelToAdd = rmfield(modelToAdd,'rxnFrom'); 0089 end 0090 if isfield(modelToAdd,'geneFrom') 0091 modelToAdd = rmfield(modelToAdd,'geneFrom'); 0092 end 0093 0094 %Merge the models 0095 model=mergeModels({model;modelToAdd},'metNames',[],true); 0096 end 0097 0098 if deleteOriginal==true 0099 model=removeReactions(model,rxns,true,true,true); %Also delete unused compartments 0100 end 0101 0102 model.id=originalID; 0103 model.name=originalName; 0104 end