0001 function compStruct=compareModels(models,printResults)
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
0028
0029
0030
0031 if nargin<2
0032 printResults=true;
0033 end
0034
0035 if numel(models)<=1
0036 dispEM('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 without 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
0119
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
0133 toCheck=false(size(toCheckA,1),numel(models));
0134 toCheck(:,I)=toCheckA;
0135
0136
0137 function I=checkField(A)
0138 I=isfield(A,field);
0139 end
0140 end
0141 function printList(models,toCheck,nElements)
0142
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
0159
0160
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