0001 function model=addRxnsGenesMets(model,sourceModel,rxns,addGene,rxnNote,confidence)
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
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 if nargin<6
0048 confidence=0;
0049 end
0050 rxns=convertCharArray(rxns);
0051 if nargin<5
0052 rxnNote={'Added via addRxnsGenesMets()'};
0053 else
0054 rxnNote=convertCharArray(rxnNote);
0055 end
0056 if numel(rxnNote)==1 && numel(rxns)>1
0057 rxnNoteArray=cell(1,numel(rxns));
0058 rxnNoteArray(:)=rxnNote;
0059 rxnNote=rxnNoteArray;
0060 end
0061 if nargin<4
0062 addGene=false;
0063 end
0064
0065
0066 [notNewRxn,oldRxn]=ismember(rxns,model.rxns);
0067 rxns=rxns(~notNewRxn);
0068 if isempty(rxns)
0069 error('All reactions are already in the model.');
0070 elseif ~isempty(notNewRxn)
0071 fprintf('The following reactions were already present in the model and will not be added:\n')
0072 fprintf([strjoin(model.rxns(oldRxn(find(oldRxn))),'\n') '\n'])
0073 end
0074
0075 [~, rxnIdx]=ismember(rxns,sourceModel.rxns);
0076 if any(rxnIdx==0)
0077 dispEM('The following reaction IDs could not be found in the source model:',true,...
0078 rxns(rxnIdx==0));
0079 end
0080
0081
0082 metIdx=find(any(sourceModel.S(:,rxnIdx),2));
0083
0084
0085
0086
0087 metCompsN =cellstr(num2str(model.metComps));
0088 map=containers.Map(cellstr(num2str(transpose([1:length(model.comps)]))),model.comps);
0089 metCompsN = map.values(metCompsN);
0090 metCompsN = strcat(model.metNames,'[',metCompsN,']');
0091
0092 sourcemetCompsN=cellstr(num2str(sourceModel.metComps));
0093 map=containers.Map(cellstr(num2str(transpose([1:length(sourceModel.comps)]))),sourceModel.comps);
0094 sourcemetCompsN = map.values(sourcemetCompsN);
0095 sourcemetCompsN=strcat(sourceModel.metNames,'[',sourcemetCompsN,']');
0096
0097 newMetCompsN=sourcemetCompsN(metIdx);
0098 notNewMet=newMetCompsN(ismember(newMetCompsN,metCompsN));
0099
0100 if ~isempty(notNewMet)
0101 fprintf('\nThe following metabolites were already present in the model and will not be added:\n')
0102 fprintf([strjoin(transpose(notNewMet),'\n') '\n'])
0103 end
0104
0105 metIdx=metIdx(~ismember(sourcemetCompsN(metIdx),metCompsN));
0106
0107 if ~isempty(metIdx)
0108 fprintf('\nThe following metabolites will be added to the model:\n')
0109 fprintf([strjoin(transpose(sourcemetCompsN(metIdx)),'\n') '\n'])
0110
0111 if isfield(sourceModel,'mets')
0112 metsToAdd.mets=sourceModel.mets(metIdx);
0113 end
0114 if isfield(sourceModel,'metNames')
0115 metsToAdd.metNames=sourceModel.metNames(metIdx);
0116 end
0117 if isfield(sourceModel,'metFormulas')
0118 metsToAdd.metFormulas=sourceModel.metFormulas(metIdx);
0119 end
0120 if isfield(sourceModel,'metCharges')
0121 metsToAdd.metCharges=sourceModel.metCharges(metIdx);
0122 end
0123 if isfield(sourceModel,'metMiriams')
0124 metsToAdd.metMiriams=sourceModel.metMiriams(metIdx);
0125 end
0126 if isfield(sourceModel,'metNotes')
0127 metsToAdd.metNotes=sourceModel.metNotes(metIdx);
0128 end
0129 if isfield(sourceModel,'inchis')
0130 metsToAdd.inchis=sourceModel.inchis(metIdx);
0131 end
0132 if isfield(sourceModel,'metSmiles')
0133 metsToAdd.metSmiles=sourceModel.metSmiles(metIdx);
0134 end
0135 if isfield(sourceModel,'metDeltaG')
0136 metsToAdd.metDeltaG=sourceModel.metDeltaG(metIdx);
0137 end
0138
0139 metsToAdd.compartments=strtrim(cellstr(num2str(sourceModel.metComps(metIdx))));
0140 [~,idx]=ismember(metsToAdd.compartments,strsplit(num2str(1:length(sourceModel.comps))));
0141 metsToAdd.compartments=sourceModel.comps(idx);
0142
0143 model=addMets(model,metsToAdd);
0144 end
0145 fprintf('\nNumber of metabolites added to the model:\n')
0146 fprintf([num2str(numel(metIdx)),'\n'])
0147
0148
0149 if ~islogical(addGene) | addGene ~= false
0150 if ischar(addGene)
0151 rxnToAdd.grRules={addGene};
0152 elseif iscell(addGene)
0153 rxnToAdd.grRules=addGene(~notNewRxn);
0154 else
0155 rxnToAdd.grRules=sourceModel.grRules(rxnIdx);
0156 end
0157 end
0158
0159 rxnToAdd.equations=constructEquations(sourceModel,rxnIdx);
0160 rxnToAdd.rxnNames=sourceModel.rxnNames(rxnIdx);
0161 rxnToAdd.rxns=sourceModel.rxns(rxnIdx);
0162 rxnToAdd.lb=sourceModel.lb(rxnIdx);
0163 rxnToAdd.ub=sourceModel.ub(rxnIdx);
0164 rxnToAdd.rxnNotes(:)=rxnNote(~notNewRxn);
0165 rxnToAdd.rxnConfidenceScores=NaN(1,numel(rxnToAdd.rxns));
0166 if ~isnumeric(confidence)
0167 EM='confidence score must be numeric';
0168 dispEM(EM, true);
0169 end
0170 rxnToAdd.rxnConfidenceScores(:)=confidence;
0171 if isfield(sourceModel,'rxnDeltaG')
0172 rxnToAdd.rxnDeltaG=sourceModel.rxnDeltaG(rxnIdx);
0173 end
0174 if isfield(sourceModel,'subSystems')
0175 rxnToAdd.subSystems=sourceModel.subSystems(rxnIdx);
0176 end
0177 if isfield(sourceModel,'eccodes')
0178 rxnToAdd.eccodes=sourceModel.eccodes(rxnIdx);
0179 end
0180 model=addRxns(model,rxnToAdd,3,'',false,true);
0181
0182 fprintf('\nNumber of reactions added to the model:\n')
0183 fprintf([num2str(numel(rxnIdx)),'\n'])
0184 end