isSameCobraModel

PURPOSE ^

isSameCobraModel Checks if two COBRA models are the same

SYNOPSIS ^

function [isSame,nDiff,commonFields] = isSameCobraModel(model1,model2)

DESCRIPTION ^

isSameCobraModel Checks if two COBRA models are the same

 [isSame,nDiff,commonFields] = isSameCobraModel(model1,model2)

INPUTS
 model1        COBRA model structure 1
 model2        COBRA model structure 2

OUTPUTS
 isSame        True if all common fields are identical, else false
 nDiff         Number of differences between the two models for each field
 commonFields  List of common fields

 Markus Herrgard 9/14/07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [isSame,nDiff,commonFields] = isSameCobraModel(model1,model2)
0002 %isSameCobraModel Checks if two COBRA models are the same
0003 %
0004 % [isSame,nDiff,commonFields] = isSameCobraModel(model1,model2)
0005 %
0006 %INPUTS
0007 % model1        COBRA model structure 1
0008 % model2        COBRA model structure 2
0009 %
0010 %OUTPUTS
0011 % isSame        True if all common fields are identical, else false
0012 % nDiff         Number of differences between the two models for each field
0013 % commonFields  List of common fields
0014 %
0015 % Markus Herrgard 9/14/07
0016 
0017 isSame = true;
0018 
0019 fields1 = fieldnames(model1);
0020 fields2 = fieldnames(model2);
0021 onlyIn1 = setdiff(fields1,fields2);
0022 onlyIn2 = setdiff(fields2,fields1);
0023 commonFields = intersect(fields1,fields2);
0024 commonFields = commonFields(~strcmpi('description',commonFields));
0025 
0026 if (~isempty(onlyIn1) & ~isempty(onlyIn2))
0027     isSame = false;
0028 end
0029 
0030 nFields = length(commonFields);
0031 
0032 nDiff = zeros(nFields,1);
0033 for i = 1:nFields
0034    fieldName = commonFields{i};
0035    value1 = getfield(model1,fieldName);
0036    value2 = getfield(model2,fieldName);
0037    if isnumeric(value1)
0038        nDiff(i) = sum(sum(value1 ~= value2));
0039    elseif iscellstr(value1)
0040        nDiff(i) = sum(~strcmp(value1,value2));
0041    elseif ischar(value1)
0042        nDiff(i) = ~strcmp(value1,value2);
0043    end
0044    if (nDiff(i) > 0)
0045        isSame = false;
0046    end
0047 end

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003