Home > RAVEN > copyToComps.m

copyToComps

PURPOSE ^

copyToComps

SYNOPSIS ^

function model=copyToComps(model,toComps,rxns,deleteOriginal,compNames,compOutside)

DESCRIPTION ^

 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-07-25

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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-07-25
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 originalID=model.id;
0046 originalDescription=model.description;
0047 
0048 rxns=getIndexes(model,rxns,'rxns');
0049 
0050 for i=1:numel(toComps)
0051    %Check if the compartment exists, otherwise add it
0052    [I J]=ismember(toComps(i),model.comps);
0053    if I==false
0054        model.comps=[model.comps;toComps(i)];
0055        model.compNames=[model.compNames;compNames(i)];
0056        if isfield(model,'compOutside')
0057            model.compOutside=[model.compOutside;compOutside(i)];
0058        end
0059        if isfield(model,'compMiriams')
0060            model.compMiriams=[model.compMiriams;cell(1,1)];
0061        end
0062        J=numel(model.comps);
0063    end
0064    %Copy the reactions by making a model structure with only them, then
0065    %change the localization, and finally merge with the original model
0066    modelToAdd=model;
0067    modelToAdd=removeRxns(modelToAdd,setdiff(1:numel(model.rxns),rxns),true,true);
0068    modelToAdd.rxns=strcat(modelToAdd.rxns,'_',toComps(i));
0069    modelToAdd.mets=strcat(modelToAdd.mets,'_',toComps(i));
0070    modelToAdd.comps=modelToAdd.comps(J);
0071    modelToAdd.compNames=modelToAdd.compNames(J);
0072    if isfield(modelToAdd,'compOutside')
0073         modelToAdd.compOutside=modelToAdd.compOutside(J);
0074    end
0075    if isfield(modelToAdd,'compMiriams')
0076         modelToAdd.compMiriams=modelToAdd.compMiriams(J);
0077    end
0078    modelToAdd.metComps=ones(numel(modelToAdd.mets),1);
0079    
0080    %Merge the models
0081    model=mergeModels({model;modelToAdd});
0082 end
0083 
0084 if deleteOriginal==true
0085    model=removeRxns(model,rxns,true,true,true); %Also delete unused compartments
0086 end
0087 
0088 model.id=originalID;
0089 model.description=originalDescription;
0090 end

Generated on Mon 06-Jan-2014 14:58:12 by m2html © 2005