Home > RAVEN > compareModels.m

compareModels

PURPOSE ^

compareModels

SYNOPSIS ^

function compStruct=compareModels(models,printResults)

DESCRIPTION ^

 compareModels
   Compares two or three 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
                       (opt, 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=compareModels(models,printResults)

   Rasmus Agren, 2011-12-13

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function compStruct=compareModels(models,printResults)
0002 % compareModels
0003 %   Compares two or three 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 %                       (opt, 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=compareModels(models,printResults)
0027 %
0028 %   Rasmus Agren, 2011-12-13
0029 %
0030 
0031 if nargin<2
0032     printResults=true;
0033 end
0034 
0035 if numel(models)<=1
0036    throw(MException('','Cannot compare only one model. Use printModelStats if you want a summary of a model')); 
0037 end
0038 
0039 compStruct.modelIDs={};
0040 for i=1:numel(models)
0041     compStruct.modelIDs=[compStruct.modelIDs;models{i}.id];
0042     models{i}.equ=constructEquations(models{i},models{i}.rxns,true,true,true);
0043     models{i}.uEqu=constructEquations(models{i},models{i}.rxns,false,true,true);
0044 end
0045 
0046 field='rxns';
0047 compStruct.rxns.comparison=getToCheck(models,field);
0048 compStruct.rxns.nElements=checkStuff(getElements(models,field),compStruct.rxns.comparison);
0049 if printResults==true
0050     fprintf('*** Comparison of reaction IDs:\n');
0051     printList(models,compStruct.rxns.comparison,compStruct.rxns.nElements);
0052     fprintf('\n\n');
0053 end
0054 
0055 field='mets';
0056 compStruct.mets.comparison=getToCheck(models,field);
0057 compStruct.mets.nElements=checkStuff(getElements(models,field),compStruct.mets.comparison);
0058 if printResults==true
0059     fprintf('*** Comparison of metabolite IDs:\n');
0060     printList(models,compStruct.mets.comparison,compStruct.mets.nElements);
0061     fprintf('\n\n');
0062 end
0063 
0064 field='genes';
0065 compStruct.genes.comparison=getToCheck(models,field);
0066 compStruct.genes.nElements=checkStuff(getElements(models,field),compStruct.genes.comparison);
0067 if printResults==true
0068     fprintf('*** Comparison of gene IDs:\n');
0069     printList(models,compStruct.genes.comparison,compStruct.genes.nElements);
0070     fprintf('\n\n');
0071 end
0072 
0073 field='eccodes';
0074 compStruct.eccodes.comparison=getToCheck(models,field);
0075 compStruct.eccodes.nElements=checkStuff(getElements(models,field),compStruct.eccodes.comparison);
0076 if printResults==true
0077     fprintf('*** Comparison of ec-numbers:\n');
0078     printList(models,compStruct.eccodes.comparison,compStruct.eccodes.nElements);
0079     fprintf('\n\n');
0080 end
0081 
0082 field='metNames';
0083 compStruct.metNames.comparison=getToCheck(models,field);
0084 compStruct.metNames.nElements=checkStuff(getElements(models,field),compStruct.metNames.comparison);
0085 if printResults==true
0086     fprintf('*** Comparison of metabolite names:\n');
0087     printList(models,compStruct.metNames.comparison,compStruct.metNames.nElements);
0088     fprintf('\n\n');
0089 end
0090 
0091 field='equ';
0092 compStruct.equ.comparison=getToCheck(models,field);
0093 compStruct.equ.nElements=checkStuff(getElements(models,field),compStruct.equ.comparison);
0094 if printResults==true
0095     fprintf('*** Comparison of equations with compartment:\n');
0096     printList(models,compStruct.equ.comparison,compStruct.equ.nElements);
0097     fprintf('\n\n');
0098 end
0099 
0100 field='uEqu';
0101 compStruct.uEqu.comparison=getToCheck(models,field);
0102 compStruct.uEqu.nElements=checkStuff(getElements(models,field),compStruct.uEqu.comparison);
0103 if printResults==true
0104     fprintf('*** Comparison of equations with compartment:\n');
0105     printList(models,compStruct.uEqu.comparison,compStruct.uEqu.nElements);
0106     fprintf('\n\n');
0107 end
0108 end
0109 function A=getElements(models,field)
0110     A={};
0111     for i=1:numel(models)
0112        if isfield(models{i},field) 
0113         A=[A;{getfield(models{i},field)}]; 
0114        end
0115     end
0116 end
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 function printList(models,toCheck,nElements)
0142     %To guess how many spaces that are needed to align
0143     firstLen=[];
0144     for i=1:size(toCheck,1)
0145        label=[];
0146        I=find(toCheck(i,:));
0147        for j=1:numel(I)
0148             label=[label models{I(j)}.id '/'];
0149        end
0150        if i==1
0151            firstLen=numel(label);
0152        end
0153        nSpaces=firstLen-numel(label);
0154        fprintf([label(1:end-1) '  ' repmat(sprintf(' '),1,nSpaces) num2str(nElements(i)) '\n']);
0155     end
0156 end
0157 function nElements=checkStuff(A,toCheck)
0158     %Now loop through the toCheck matrix, starting with the combination with the
0159     %most models. Only elements that weren't in iteration n are considered in
0160     %iteration n+1.
0161     nElements=zeros(size(toCheck,1),1);
0162     alreadyChecked=[];
0163     for i=1:size(toCheck,1)
0164         I=find(toCheck(i,:));
0165         inCommon=setdiff(A{I(1)},alreadyChecked);
0166         for j=2:numel(I)
0167            inCommon=intersect(inCommon,A{I(j)}); 
0168         end
0169         alreadyChecked=union(alreadyChecked,inCommon);
0170         nElements(i)=numel(inCommon);
0171     end
0172 end

Generated on Tue 23-Apr-2013 15:18:37 by m2html © 2005