0001 function [model, removedRxns, idxDuplRxns]=replaceMets(model,metabolite,replacement,verbose)
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 metabolite=char(metabolite);
0028 replacement=char(replacement);
0029
0030 if nargin<4
0031 verbose=false;
0032 end
0033
0034
0035
0036
0037 repIdx = find(strcmp(replacement,model.metNames));
0038 if isempty(repIdx)
0039 error('The replacement metabolite name cannot be found in the model.');
0040 end
0041
0042
0043 metIdx = find(strcmp(metabolite,model.metNames));
0044 if isempty(metIdx)
0045 error('The to-be-replaced metabolite name cannot be found in the model.');
0046 end
0047 if verbose==true
0048 fprintf('\n\nThe following reactions contain the replaced metabolite as reactant:\n')
0049 fprintf(strjoin(model.rxns(find(model.S(metIdx,:))),'\n'))
0050 fprintf('\n')
0051 end
0052 model.metNames(metIdx) = model.metNames(repIdx(1));
0053 if isfield(model,'metFormulas')
0054 model.metFormulas(metIdx) = model.metFormulas(repIdx(1));
0055 end
0056 if isfield(model,'metMiriams')
0057 model.metMiriams(metIdx) = model.metMiriams(repIdx(1));
0058 end
0059 if isfield(model,'metCharges')
0060 model.metCharges(metIdx) = model.metCharges(repIdx(1));
0061 end
0062 if isfield(model,'metDeltaG')
0063 model.metDeltaG(metIdx) = model.metDeltaG(repIdx(1));
0064 end
0065 if isfield(model,'inchis')
0066 model.inchis(metIdx) = model.inchis(repIdx(1));
0067 end
0068 if isfield(model,'metSmiles')
0069 model.metSmiles(metIdx) = model.metSmiles(repIdx(1));
0070 end
0071
0072
0073
0074
0075
0076
0077 metCompsN =cellstr(num2str(model.metComps));
0078 map = containers.Map(cellstr(num2str(transpose(1:length(model.comps)))),model.comps);
0079 metCompsN = map.values(metCompsN);
0080 metCompsN = strcat(lower(model.metNames),'[',metCompsN,']');
0081
0082 idxDelete=[];
0083 for i = 1:length(repIdx)
0084 metCompsNidx=find(strcmp(metCompsN(repIdx(i)), metCompsN));
0085 if length(metCompsNidx)>1
0086 for j = 2:length(metCompsNidx)
0087 model.S(metCompsNidx(1),:) = model.S(metCompsNidx(1),:) + model.S(metCompsNidx(j),:);
0088 idxDelete=[idxDelete; metCompsNidx(j)];
0089 end
0090 end
0091 end
0092
0093 if ~isempty(idxDelete)
0094 model.S(idxDelete,:) =[];
0095 model.mets(idxDelete) = [];
0096 model.metNames(idxDelete) = [];
0097 model.metComps(idxDelete) = [];
0098 model.b(idxDelete) = [];
0099 if isfield(model,'metFormulas')
0100 model.metFormulas(idxDelete) = [];
0101 end
0102 if isfield(model,'unconstrained')
0103 model.unconstrained(idxDelete) = [];
0104 end
0105 if isfield(model,'metMiriams')
0106 model.metMiriams(idxDelete) = [];
0107 end
0108 if isfield(model,'metCharges')
0109 model.metCharges(idxDelete) = [];
0110 end
0111 if isfield(model,'metDeltaG')
0112 model.metDeltaG(idxDelete) = [];
0113 end
0114 if isfield(model,'inchis')
0115 model.inchis(idxDelete) = [];
0116 end
0117 if isfield(model,'metSmiles')
0118 model.metSmiles(idxDelete) = [];
0119 end
0120 if isfield(model,'metFrom')
0121 model.metFrom(idxDelete) = [];
0122 end
0123 end
0124
0125
0126 model=contractModel(model,[],repIdx);
0127 end