0001 function newModel=addGenesRaven(model,genesToAdd)
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 newModel=model;
0028
0029 if isempty(genesToAdd)
0030 return;
0031 end
0032
0033
0034 if ~isfield(genesToAdd,'genes')
0035 EM='genes is a required field in genesToAdd';
0036 dispEM(EM);
0037 else
0038 genesToAdd.genes=convertCharArray(genesToAdd.genes);
0039 end
0040
0041
0042 nGenes=numel(genesToAdd.genes);
0043 nOldGenes=numel(model.genes);
0044 filler=cell(nGenes,1);
0045 filler(:)={''};
0046 largeFiller=cell(nOldGenes,1);
0047 largeFiller(:)={''};
0048
0049
0050 I=ismember(genesToAdd.genes,model.genes);
0051 if all(I)
0052 warning('All genes in genesToAdd.genes are already present in model.genes');
0053 return
0054 elseif any(I)
0055 existingGenes=strjoin(genesToAdd.genes(I), ', ');
0056 warning(['The following genes are already present in model.genes and will therefore not be added: ', existingGenes])
0057 genesToAdd.genes(I)=[];
0058 if isfield(genesToAdd,'geneShortNames')
0059 genesToAdd.geneShortNames(I)=[];
0060 end
0061 if isfield(genesToAdd,'proteins')
0062 genesToAdd.proteins(I)=[];
0063 end
0064 if isfield(genesToAdd,'geneMiriams')
0065 genesToAdd.geneMiriams(I)=[];
0066 end
0067 else
0068 newModel.genes=[newModel.genes;genesToAdd.genes(:)];
0069 end
0070
0071
0072 if isfield(genesToAdd,'geneShortNames')
0073 genesToAdd.geneShortNames=convertCharArray(genesToAdd.geneShortNames);
0074 if numel(genesToAdd.geneShortNames)~=nGenes
0075 EM='genesToAdd.geneShortNames must have the same number of elements as genesToAdd.genes';
0076 dispEM(EM);
0077 end
0078
0079 if ~isfield(newModel,'geneShortNames')
0080 newModel.geneShortNames=largeFiller;
0081 end
0082 newModel.geneShortNames=[newModel.geneShortNames;genesToAdd.geneShortNames(:)];
0083 else
0084
0085 if isfield(newModel,'geneShortNames')
0086 newModel.geneShortNames=[newModel.geneShortNames;filler];
0087 end
0088 end
0089 if isfield(genesToAdd,'proteins')
0090 genesToAdd.proteins=convertCharArray(genesToAdd.proteins);
0091 if numel(genesToAdd.proteins)~=nGenes
0092 EM='genesToAdd.proteins must have the same number of elements as genesToAdd.genes';
0093 dispEM(EM);
0094 end
0095
0096 if ~isfield(newModel,'proteins')
0097 newModel.proteins=largeFiller;
0098 end
0099 newModel.proteins=[newModel.proteins;genesToAdd.proteins(:)];
0100 else
0101
0102 if isfield(newModel,'proteins')
0103 newModel.proteins=[newModel.proteins;filler];
0104 end
0105 end
0106
0107
0108
0109 if isfield(genesToAdd,'geneMiriams')
0110 if numel(genesToAdd.geneMiriams)~=nGenes
0111 EM='genesToAdd.geneMiriams must have the same number of elements as genesToAdd.genes';
0112 dispEM(EM);
0113 end
0114
0115 if ~isfield(newModel,'geneMiriams')
0116 newModel.geneMiriams=cell(nOldGenes,1);
0117 end
0118 newModel.geneMiriams=[newModel.geneMiriams;genesToAdd.geneMiriams(:)];
0119 else
0120 if isfield(newModel,'geneMiriams')
0121 newModel.geneMiriams=[newModel.geneMiriams;cell(nGenes,1)];
0122 end
0123 end
0124
0125 if isfield(genesToAdd,'geneComps')
0126 if numel(genesToAdd.geneComps)~=nGenes
0127 EM='genesToAdd.geneComps must have the same number of elements as genesToAdd.genes';
0128 dispEM(EM);
0129 end
0130
0131 if ~isfield(newModel,'geneComps')
0132 newModel.geneComps=ones(nOldGenes,1);
0133 EM='Adding genes with compartment information to a model without such information. All existing genes will be assigned to the first compartment';
0134 dispEM(EM,false);
0135 end
0136 newModel.geneComps=[newModel.geneComps;genesToAdd.geneComps(:)];
0137 else
0138 if isfield(newModel,'geneComps')
0139 newModel.geneComps=[newModel.geneComps;ones(nGenes,1)];
0140 fprintf('NOTE: The added genes will be assigned to the first compartment\n');
0141 end
0142 end
0143
0144 if isfield(newModel,'geneFrom')
0145 newModel.geneFrom=[newModel.geneFrom;filler];
0146 end
0147
0148 if isfield(newModel,'rxnGeneMat')
0149 newModel.rxnGeneMat=[newModel.rxnGeneMat,zeros(length(newModel.rxns),nGenes)];
0150 end
0151 end