0001 function [model, addedRxns]=addTransport(model,fromComp,toComps,metNames,isRev,onlyToExisting,prefix)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 fromComp=char(fromComp);
0029 [I, fromID]=ismember(model.comps,fromComp);
0030 fromID=find(fromID);
0031 if sum(I)~=1
0032 EM='fromComps must have exactly one match in model.comps';
0033 dispEM(EM);
0034 end
0035 toComps=convertCharArray(toComps);
0036 [I, toIDs]=ismember(toComps,model.comps);
0037 if ~all(I)
0038 EM='All compartments in toComps must have a match in model.comps';
0039 dispEM(EM);
0040 end
0041 if nargin<4
0042
0043 metNames=model.metNames(model.metComps==fromID);
0044 elseif isempty(metNames)
0045
0046 metNames=model.metNames(ismember(model.metComps,model.comps(fromID)));
0047 else
0048 metNames=convertCharArray(metNames);
0049 end
0050
0051 if nargin<5
0052 isRev=true;
0053 end
0054 if nargin<6
0055 onlyToExisting=true;
0056 end
0057 if nargin<7
0058 prefix='tr_';
0059 else
0060 prefix=char(prefix);
0061 end
0062
0063
0064 if numel(unique(metNames))~=numel(metNames)
0065 dispEM('Not all metabolite names are unique');
0066 end
0067
0068
0069 I=find(model.metComps==fromID);
0070 [J, K]=ismember(metNames,model.metNames(I));
0071 if ~all(J)
0072 EM='Not all metabolites in metNames exist in fromComp';
0073 dispEM(EM);
0074 end
0075 fromMets=I(K);
0076 addedRxns={};
0077
0078 for i=1:numel(toComps)
0079 fromMetsInComp=fromMets;
0080
0081 I=find(model.metComps==toIDs(i));
0082 [J, K]=ismember(metNames,model.metNames(I));
0083 if onlyToExisting==true || all(J)
0084 toMets=I(K(J));
0085 fromMetsInComp=fromMetsInComp(J);
0086 else
0087
0088
0089 metsToAdd.metNames=metNames(J==0);
0090 metsToAdd.compartments=toComps{i};
0091 model=addMets(model,metsToAdd);
0092
0093
0094
0095 I=find(model.metComps==toIDs(i));
0096 [~, K]=ismember(metNames,model.metNames(I));
0097 toMets=I(K);
0098 end
0099
0100
0101 nRxns=numel(fromMetsInComp);
0102 newS=zeros(numel(model.mets),nRxns);
0103 newS(sub2ind(size(newS),fromMetsInComp(:),(1:nRxns)'))=-1;
0104 newS(sub2ind(size(newS),toMets(:),(1:nRxns)'))=1;
0105
0106
0107 model.S=[model.S sparse(newS)];
0108 if isfield(model.annotation,'defaultLB')
0109 lb = model.annotation.defaultLB;
0110 ub = model.annotation.defaultUB;
0111 else
0112 lb = -inf;
0113 ub = inf;
0114 end
0115 if isRev==true
0116 model.lb=[model.lb;ones(nRxns,1)*lb];
0117 model.rev=[model.rev;ones(nRxns,1)];
0118 else
0119 model.lb=[model.lb;zeros(nRxns,1)];
0120 model.rev=[model.rev;zeros(nRxns,1)];
0121 end
0122 model.ub=[model.ub;ones(nRxns,1)*ub];
0123 model.c=[model.c;zeros(nRxns,1)];
0124
0125
0126 filler=cell(nRxns,1);
0127 filler(:)={''};
0128 addedRxnsID=generateNewIds(model,'rxns',prefix,nRxns);
0129 addedRxnsName=transpose(strcat(metNames, {' transport, '}, model.compNames(fromID), '-', model.compNames(toIDs(i))));
0130 model.rxns=[model.rxns;addedRxnsID];
0131 model.rxnNames=[model.rxnNames;addedRxnsName];
0132
0133 if isfield(model,'eccodes')
0134 model.eccodes=[model.eccodes;filler];
0135 end
0136 if isfield(model,'subSystems')
0137 ssFiller=filler;
0138 if isRev==1
0139 ssFiller(:)={{['Transport between ' fromComp ' and ' toComps{i}]}};
0140 else
0141 ssFiller(:)={{['Transport from ' fromComp ' to ' toComps{i}]}};
0142 end
0143 model.subSystems=[model.subSystems;ssFiller];
0144 end
0145 if isfield(model,'grRules')
0146 model.grRules=[model.grRules;filler];
0147 end
0148 if isfield(model,'rxnFrom')
0149 model.rxnFrom=[model.rxnFrom;filler];
0150 end
0151 if isfield(model,'rxnMiriams')
0152 model.rxnMiriams=[model.rxnMiriams;cell(nRxns,1)];
0153 end
0154 if isfield(model,'rxnComps')
0155 model.rxnComps=[model.rxnComps;ones(nRxns,1)];
0156 fprintf('NOTE: The added transport reactions will be added to the first compartment\n');
0157 end
0158 if isfield(model,'rxnGeneMat')
0159 model.rxnGeneMat=[model.rxnGeneMat;sparse(nRxns,numel(model.genes))];
0160 end
0161 if isfield(model,'rxnNotes')
0162 model.rxnNotes=[model.rxnNotes;filler];
0163 end
0164 if isfield(model,'rxnReferences')
0165 model.rxnReferences=[model.rxnReferences;filler];
0166 end
0167 if isfield(model,'rxnConfidenceScores')
0168 model.rxnConfidenceScores=[model.rxnConfidenceScores;ones(nRxns,1)];
0169 end
0170 if isfield(model,'rxnDeltaG')
0171 model.rxnDeltaG=[model.rxnDeltaG;zeros(nRxns,1)];
0172 end
0173 addedRxns = [addedRxns; addedRxnsID];
0174 end
0175 end