Home > core > compareRxnsGenesMetsComps.m

compareRxnsGenesMetsComps

PURPOSE ^

compareRxnsGenesMetsComps

SYNOPSIS ^

function compStruct=compareRxnsGenesMetsComps(models,printResults)

DESCRIPTION ^

 compareRxnsGenesMetsComps
   Compares two or more models with respect to overlap in terms of genes,
   reactions, metabolites and compartments.

   models              cell array of two or more models
   printResults        true if the results should be printed on the screen
                       (optional, default false)

   compStruct          structure that contains the comparison
       modelIDs        cell array of model ids
       rxns            These contain the comparison for each field. 'equ' are
                       the equations after sorting and 'uEqu' are the
                       equations when not taking compartmentalization into acount
       mets
       genes
       eccodes
       metNames
       equ
       uEqu
           comparison    binary matrix where each row indicate which models are
                       included in the comparison
           nElements   vector with the number of elements for each
                       comparison

 Usage: compStruct=compareRxnsGenesMetsComps(models,printResults)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function compStruct=compareRxnsGenesMetsComps(models,printResults)
0002 % compareRxnsGenesMetsComps
0003 %   Compares two or more models with respect to overlap in terms of genes,
0004 %   reactions, metabolites and compartments.
0005 %
0006 %   models              cell array of two or more models
0007 %   printResults        true if the results should be printed on the screen
0008 %                       (optional, default false)
0009 %
0010 %   compStruct          structure that contains the comparison
0011 %       modelIDs        cell array of model ids
0012 %       rxns            These contain the comparison for each field. 'equ' are
0013 %                       the equations after sorting and 'uEqu' are the
0014 %                       equations when not taking compartmentalization into acount
0015 %       mets
0016 %       genes
0017 %       eccodes
0018 %       metNames
0019 %       equ
0020 %       uEqu
0021 %           comparison    binary matrix where each row indicate which models are
0022 %                       included in the comparison
0023 %           nElements   vector with the number of elements for each
0024 %                       comparison
0025 %
0026 % Usage: compStruct=compareRxnsGenesMetsComps(models,printResults)
0027 
0028 if nargin<2
0029     printResults=true;
0030 end
0031 
0032 if numel(models)<=1
0033     EM='Cannot compare only one model. Use printModelStats if you want a summary of a model';
0034     dispEM(EM);
0035 end
0036 
0037 compStruct.modelIDs={};
0038 for i=1:numel(models)
0039     compStruct.modelIDs=[compStruct.modelIDs;models{i}.id];
0040     models{i}.equ=constructEquations(models{i},models{i}.rxns,true,true,true);
0041     models{i}.uEqu=constructEquations(models{i},models{i}.rxns,false,true,true);
0042 end
0043 
0044 field='rxns';
0045 compStruct.rxns.comparison=getToCheck(models,field);
0046 compStruct.rxns.nElements=checkStuff(getElements(models,field),compStruct.rxns.comparison);
0047 if printResults==true
0048     fprintf('*** Comparison of reaction IDs:\n');
0049     printList(models,compStruct.rxns.comparison,compStruct.rxns.nElements);
0050     fprintf('\n\n');
0051 end
0052 
0053 field='mets';
0054 compStruct.mets.comparison=getToCheck(models,field);
0055 compStruct.mets.nElements=checkStuff(getElements(models,field),compStruct.mets.comparison);
0056 if printResults==true
0057     fprintf('*** Comparison of metabolite IDs:\n');
0058     printList(models,compStruct.mets.comparison,compStruct.mets.nElements);
0059     fprintf('\n\n');
0060 end
0061 
0062 field='genes';
0063 compStruct.genes.comparison=getToCheck(models,field);
0064 compStruct.genes.nElements=checkStuff(getElements(models,field),compStruct.genes.comparison);
0065 if printResults==true
0066     fprintf('*** Comparison of gene IDs:\n');
0067     printList(models,compStruct.genes.comparison,compStruct.genes.nElements);
0068     fprintf('\n\n');
0069 end
0070 
0071 field='eccodes';
0072 compStruct.eccodes.comparison=getToCheck(models,field);
0073 compStruct.eccodes.nElements=checkStuff(getElements(models,field),compStruct.eccodes.comparison);
0074 if printResults==true
0075     fprintf('*** Comparison of ec-numbers:\n');
0076     printList(models,compStruct.eccodes.comparison,compStruct.eccodes.nElements);
0077     fprintf('\n\n');
0078 end
0079 
0080 field='metNames';
0081 compStruct.metNames.comparison=getToCheck(models,field);
0082 compStruct.metNames.nElements=checkStuff(getElements(models,field),compStruct.metNames.comparison);
0083 if printResults==true
0084     fprintf('*** Comparison of metabolite names:\n');
0085     printList(models,compStruct.metNames.comparison,compStruct.metNames.nElements);
0086     fprintf('\n\n');
0087 end
0088 
0089 field='equ';
0090 compStruct.equ.comparison=getToCheck(models,field);
0091 compStruct.equ.nElements=checkStuff(getElements(models,field),compStruct.equ.comparison);
0092 if printResults==true
0093     fprintf('*** Comparison of equations with compartment:\n');
0094     printList(models,compStruct.equ.comparison,compStruct.equ.nElements);
0095     fprintf('\n\n');
0096 end
0097 
0098 field='uEqu';
0099 compStruct.uEqu.comparison=getToCheck(models,field);
0100 compStruct.uEqu.nElements=checkStuff(getElements(models,field),compStruct.uEqu.comparison);
0101 if printResults==true
0102     fprintf('*** Comparison of equations without compartment:\n');
0103     printList(models,compStruct.uEqu.comparison,compStruct.uEqu.nElements);
0104     fprintf('\n\n');
0105 end
0106 end
0107 
0108 function A=getElements(models,field)
0109 A={};
0110 for i=1:numel(models)
0111     if isfield(models{i},field)
0112         A=[A;{models{i}.(field)}];
0113     end
0114 end
0115 end
0116 
0117 function toCheck=getToCheck(models,field)
0118 %Get all the combinations that should be checked for overlap (including the
0119 %single ones)
0120 toCheckA=[];
0121 I=find(cellfun(@checkField,models));
0122 nI=numel(I);
0123 for i=nI:-1:1
0124     combs=combnk(1:nI,i);
0125     toAdd=false(size(combs,1),nI);
0126     for j=1:size(combs,1)
0127         toAdd(j,combs(j,:))=true;
0128     end
0129     toCheckA=[toCheckA;toAdd];
0130 end
0131 
0132 %If not all of the models have the required field
0133 toCheck=false(size(toCheckA,1),numel(models));
0134 toCheck(:,I)=toCheckA;
0135 
0136 %Ugly thing to get around parameters
0137     function I=checkField(A)
0138         I=isfield(A,field);
0139     end
0140 end
0141 
0142 function printList(models,toCheck,nElements)
0143 %To guess how many spaces that are needed to align
0144 firstLen=[];
0145 for i=1:size(toCheck,1)
0146     label=[];
0147     I=find(toCheck(i,:));
0148     for j=1:numel(I)
0149         label=[label models{I(j)}.id '/'];
0150     end
0151     if i==1
0152         firstLen=numel(label);
0153     end
0154     nSpaces=firstLen-numel(label);
0155     fprintf([label(1:end-1) '  ' repmat(sprintf(' '),1,nSpaces) num2str(nElements(i)) '\n']);
0156 end
0157 end
0158 
0159 function nElements=checkStuff(A,toCheck)
0160 %Now loop through the toCheck matrix, starting with the combination with
0161 %the most models. Only elements that weren't in iteration n are considered
0162 %in iteration n+1.
0163 nElements=zeros(size(toCheck,1),1);
0164 alreadyChecked=[];
0165 for i=1:size(toCheck,1)
0166     I=find(toCheck(i,:));
0167     inCommon=setdiff(A{I(1)},alreadyChecked);
0168     for j=2:numel(I)
0169         inCommon=intersect(inCommon,A{I(j)});
0170     end
0171     alreadyChecked=union(alreadyChecked,inCommon);
0172     nElements(i)=numel(inCommon);
0173 end
0174 end

Generated by m2html © 2005