0001 function [model addedRxns]=addTransport(model,fromComp,toComps,metNames,isRev,onlyToExisting)
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 if iscell(fromComp)
0028 fromComp=fromComp{1};
0029 end
0030 [I fromID]=ismember(model.comps,fromComp);
0031 fromID=find(fromID);
0032 if sum(I)~=1
0033 throw(MException('','fromComps must have exactly one match in model.comps'));
0034 end
0035 if ischar(toComps)
0036 toComps={toComps};
0037 end
0038 [I toIDs]=ismember(toComps,model.comps);
0039 if ~all(I)
0040 throw(MException('','All compartments in toComps must have a match in model.comps'));
0041 end
0042 if nargin<4
0043
0044 metNames=model.metNames(model.metComps==fromID);
0045 end
0046
0047
0048 if isempty(metNames)
0049
0050 metNames=model.metNames(ismember(model.metComps,model.comps(fromID)));
0051 end
0052
0053 if nargin<5
0054 isRev=true;
0055 end
0056 if nargin<6
0057 onlyToExisting=true;
0058 end
0059
0060
0061 if numel(unique(metNames))~=numel(metNames)
0062 throw(MException('','Not all metabolite names are unique'));
0063 end
0064
0065
0066 I=find(model.metComps==fromID);
0067 [J K]=ismember(metNames,model.metNames(I));
0068 if ~all(J)
0069 throw(MException('','Not all metabolites in metNames exist in fromComp'));
0070 end
0071 fromMets=I(K);
0072
0073
0074 for i=1:numel(toComps)
0075 fromMetsInComp=fromMets;
0076
0077 I=find(model.metComps==toIDs(i));
0078 [J K]=ismember(metNames,model.metNames(I));
0079 if onlyToExisting==true || all(J)
0080 toMets=I(K(J));
0081 fromMetsInComp=fromMetsInComp(J);
0082 else
0083
0084
0085 metsToAdd.metNames=metNames(J==0);
0086 metsToAdd.compartments=toComps{i};
0087 model=addMets(model,metsToAdd);
0088
0089
0090
0091 I=find(model.metComps==toIDs(i));
0092 [crap K]=ismember(metNames,model.metNames(I));
0093 toMets=I(K);
0094 end
0095
0096
0097 nRxns=numel(fromMetsInComp);
0098 newS=zeros(numel(model.mets),nRxns);
0099 newS(sub2ind(size(newS),fromMetsInComp(:),(1:nRxns)'))=-1;
0100 newS(sub2ind(size(newS),toMets(:),(1:nRxns)'))=1;
0101
0102
0103 model.S=[model.S sparse(newS)];
0104 if isRev==true
0105 model.lb=[model.lb;ones(nRxns,1)*-inf];
0106 model.rev=[model.rev;ones(nRxns,1)];
0107 else
0108 model.lb=[model.lb;zeros(nRxns,1)];
0109 model.rev=[model.rev;zeros(nRxns,1)];
0110 end
0111 model.ub=[model.ub;ones(nRxns,1)*inf];
0112 model.c=[model.c;zeros(nRxns,1)];
0113
0114
0115 filler=cell(nRxns,1);
0116 filler(:)={''};
0117 addedRxns=strcat({['T_' fromComp '_to_' toComps{i} '_']},model.mets(fromMetsInComp));
0118 model.rxns=[model.rxns;addedRxns];
0119 model.rxnNames=[model.rxnNames;addedRxns];
0120
0121 if isfield(model,'eccodes')
0122 model.eccodes=[model.eccodes;filler];
0123 end
0124 if isfield(model,'subSystems')
0125 ssFiller=filler;
0126 if isRev==1
0127 ssFiller(:)={['Transport between ' fromComp ' and ' toComps{i}]};
0128 else
0129 ssFiller(:)={['Transport from ' fromComp ' to ' toComps{i}]};
0130 end
0131 model.subSystems=[model.subSystems;ssFiller];
0132 end
0133 if isfield(model,'grRules')
0134 model.grRules=[model.grRules;filler];
0135 end
0136 if isfield(model,'rxnFrom')
0137 model.rxnFrom=[model.rxnFrom;filler];
0138 end
0139 if isfield(model,'rxnGeneMat')
0140 model.rxnGeneMat=[model.rxnGeneMat;sparse(nRxns,numel(model.genes))];
0141 end
0142 end
0143 end