Home > core > addGenesRaven.m

addGenesRaven

PURPOSE ^

addGenesRaven

SYNOPSIS ^

function newModel=addGenesRaven(model,genesToAdd)

DESCRIPTION ^

 addGenesRaven
   Adds genes to a model

   model        a model structure
   genesToAdd   the genes genesToAdd can have the following fields:
                genes          cell array with unique strings that
                               identifies each gene. Only character which are
                               allowed in SBML ids are allowed (mainly a-z,
                               0-9 and '_'). However, there is no check
                               for this performed, as it only matters if
                               the model should be exported to SBML
                geneShortNames cell array of gene abbreviations (optional,
                               default '')
                geneMiriams    cell array with MIRIAM structures (optional,
                               default [])
                proteins   cell array of protein names associated to
                               each gene (optional, default '')

   newModel     an updated model structure

   NOTE: This function does not make extensive checks about MIRIAM formats,
   forbidden characters or such.

 Usage: newModel=addGenesRaven(model,genesToAdd)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function newModel=addGenesRaven(model,genesToAdd)
0002 % addGenesRaven
0003 %   Adds genes to a model
0004 %
0005 %   model        a model structure
0006 %   genesToAdd   the genes genesToAdd can have the following fields:
0007 %                genes          cell array with unique strings that
0008 %                               identifies each gene. Only character which are
0009 %                               allowed in SBML ids are allowed (mainly a-z,
0010 %                               0-9 and '_'). However, there is no check
0011 %                               for this performed, as it only matters if
0012 %                               the model should be exported to SBML
0013 %                geneShortNames cell array of gene abbreviations (optional,
0014 %                               default '')
0015 %                geneMiriams    cell array with MIRIAM structures (optional,
0016 %                               default [])
0017 %                proteins   cell array of protein names associated to
0018 %                               each gene (optional, default '')
0019 %
0020 %   newModel     an updated model structure
0021 %
0022 %   NOTE: This function does not make extensive checks about MIRIAM formats,
0023 %   forbidden characters or such.
0024 %
0025 % Usage: newModel=addGenesRaven(model,genesToAdd)
0026 
0027 newModel=model;
0028 
0029 if isempty(genesToAdd)
0030     return;
0031 end
0032 
0033 %Check some stuff regarding the required fields
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 %Number of genes
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 %Check that no gene ids are already present in the model
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 %Some more checks and if they pass then add each field to the structure
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     %Add empty field if it doesn't exist
0079     if ~isfield(newModel,'geneShortNames')
0080         newModel.geneShortNames=largeFiller;
0081     end
0082     newModel.geneShortNames=[newModel.geneShortNames;genesToAdd.geneShortNames(:)];
0083 else
0084     %Add empty strings if structure is in model
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     %Add empty field if it doesn't exist
0096     if ~isfield(newModel,'proteins')
0097         newModel.proteins=largeFiller;
0098     end
0099     newModel.proteins=[newModel.proteins;genesToAdd.proteins(:)];
0100 else
0101     %Add empty strings if structure is in model
0102     if isfield(newModel,'proteins')
0103         newModel.proteins=[newModel.proteins;filler];
0104     end
0105 end
0106 
0107 
0108 %Don't check the type of geneMiriams
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     %Add empty field if it doesn't exist
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     %Add empty field if it doesn't exist
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

Generated by m2html © 2005