0001 function reducedModel=removeReactions(model,rxnsToRemove,removeUnusedMets,removeUnusedGenes,removeUnusedComps)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 if nargin<3
0024 removeUnusedMets=false;
0025 end
0026 if nargin<4
0027 removeUnusedGenes=false;
0028 end
0029 if nargin<5
0030 removeUnusedComps=false;
0031 end
0032 if ~islogical(rxnsToRemove) && ~isnumeric(rxnsToRemove)
0033 rxnsToRemove=convertCharArray(rxnsToRemove);
0034 end
0035
0036 reducedModel=model;
0037
0038 if ~isempty(rxnsToRemove) || removeUnusedMets || removeUnusedGenes
0039 indexesToDelete=getIndexes(model,rxnsToRemove,'rxns');
0040
0041
0042 if ~isempty(indexesToDelete)
0043 reducedModel.rxns(indexesToDelete)=[];
0044 if isfield(reducedModel,'lb')
0045 reducedModel.lb(indexesToDelete)=[];
0046 end
0047 if isfield(reducedModel,'ub')
0048 reducedModel.ub(indexesToDelete)=[];
0049 end
0050 if isfield(reducedModel,'rev')
0051 reducedModel.rev(indexesToDelete)=[];
0052 end
0053 if isfield(reducedModel,'c')
0054 reducedModel.c(indexesToDelete)=[];
0055 end
0056 if isfield(reducedModel,'S')
0057 reducedModel.S(:,indexesToDelete)=[];
0058 end
0059 if isfield(reducedModel,'rxnNames')
0060 reducedModel.rxnNames(indexesToDelete)=[];
0061 end
0062 if isfield(reducedModel,'rxnGeneMat')
0063 reducedModel.rxnGeneMat(indexesToDelete,:)=[];
0064 end
0065 if isfield(reducedModel,'grRules')
0066 reducedModel.grRules(indexesToDelete,:)=[];
0067 end
0068 if isfield(reducedModel,'subSystems')
0069 reducedModel.subSystems(indexesToDelete,:)=[];
0070 end
0071 if isfield(reducedModel,'eccodes')
0072 reducedModel.eccodes(indexesToDelete,:)=[];
0073 end
0074 if isfield(reducedModel,'equations')
0075 reducedModel.equations(indexesToDelete,:)=[];
0076 end
0077 if isfield(reducedModel,'rxnMiriams')
0078 reducedModel.rxnMiriams(indexesToDelete,:)=[];
0079 end
0080 if isfield(reducedModel,'rxnComps')
0081 reducedModel.rxnComps(indexesToDelete,:)=[];
0082 end
0083 if isfield(reducedModel,'rxnFrom')
0084 reducedModel.rxnFrom(indexesToDelete,:)=[];
0085 end
0086 if isfield(reducedModel,'rxnScores')
0087 reducedModel.rxnScores(indexesToDelete,:)=[];
0088 end
0089 if isfield(reducedModel,'rxnNotes')
0090 reducedModel.rxnNotes(indexesToDelete,:)=[];
0091 end
0092 if isfield(reducedModel,'rxnReferences')
0093 reducedModel.rxnReferences(indexesToDelete,:)=[];
0094 end
0095 if isfield(reducedModel,'rxnConfidenceScores')
0096 reducedModel.rxnConfidenceScores(indexesToDelete,:)=[];
0097 end
0098 if isfield(reducedModel,'rxnDeltaG')
0099 reducedModel.rxnDeltaG(indexesToDelete,:)=[];
0100 end
0101 if isfield(reducedModel,'pwys')
0102 reducedModel.pwys(indexesToDelete,:)=[];
0103 end
0104 if isfield(reducedModel,'spontaneous')
0105 reducedModel.spontaneous(indexesToDelete)=[];
0106 end
0107 end
0108
0109
0110 if removeUnusedMets==true
0111 if isfield(reducedModel,'S')
0112 [usedMets, ~]=find(reducedModel.S);
0113 unUsedMets=true(numel(reducedModel.mets),1);
0114 unUsedMets(usedMets)=false;
0115 reducedModel=removeMets(reducedModel,unUsedMets,false,false,false,removeUnusedComps);
0116 end
0117 end
0118
0119
0120 if removeUnusedGenes==true && isfield(reducedModel,'rxnGeneMat')
0121
0122 [~, b]=find(reducedModel.rxnGeneMat);
0123 toKeep=false(numel(reducedModel.genes),1);
0124 toKeep(b)=true;
0125
0126 reducedModel.genes=reducedModel.genes(toKeep);
0127 reducedModel.rxnGeneMat=reducedModel.rxnGeneMat(:,toKeep);
0128
0129 if isfield(reducedModel,'geneShortNames')
0130 reducedModel.geneShortNames=reducedModel.geneShortNames(toKeep);
0131 end
0132
0133 if isfield(reducedModel,'proteins')
0134 reducedModel.proteins=reducedModel.proteins(toKeep);
0135 end
0136
0137 if isfield(reducedModel,'geneMiriams')
0138 reducedModel.geneMiriams=reducedModel.geneMiriams(toKeep);
0139 end
0140
0141 if isfield(reducedModel,'geneFrom')
0142 reducedModel.geneFrom=reducedModel.geneFrom(toKeep);
0143 end
0144
0145 if isfield(reducedModel,'geneComps')
0146 reducedModel.geneComps=reducedModel.geneComps(toKeep);
0147 end
0148 end
0149 else
0150 reducedModel=model;
0151 end
0152 end