standardizeModelFieldOrder Orders fields of RAVEN model structure as specified at https://github.com/SysBioChalmers/RAVEN/wiki/RAVEN-Model-Structure Input: model model structure, either RAVEN or COBRA format Output: orderedModel model structure with ordered fields The model fields themselves are not changed, only the order is modified. For changing model fields between RAVEN and COBRA format, use ravenCobraWrapper(). Usage: orderedModel=standardizeModelFieldOrder(model)
0001 function orderedModel=standardizeModelFieldOrder(model) 0002 % standardizeModelFieldOrder 0003 % Orders fields of RAVEN model structure as specified at 0004 % https://github.com/SysBioChalmers/RAVEN/wiki/RAVEN-Model-Structure 0005 % 0006 % Input: model model structure, either RAVEN or COBRA format 0007 % 0008 % Output: orderedModel model structure with ordered fields 0009 % 0010 % The model fields themselves are not changed, only the order is 0011 % modified. For changing model fields between RAVEN and COBRA format, use 0012 % ravenCobraWrapper(). 0013 % 0014 % Usage: orderedModel=standardizeModelFieldOrder(model) 0015 0016 ravenPath=findRAVENroot(); 0017 0018 if ~isfield(model,'rules') % Check if model is RAVEN 0019 fid = fopen(fullfile(ravenPath,'struct_conversion','orderRavenFields.csv')); 0020 fields = textscan(fid,'%s','Delimiter',',','HeaderLines',0); 0021 fields = fields{1}; 0022 fclose(fid); 0023 else % If model is COBRA 0024 fid = fopen(fullfile(ravenPath,'struct_conversion','COBRA_structure_fields.csv')); % Taken from https://github.com/opencobra/cobratoolbox/blob/develop/src/base/io/definitions/COBRA_structure_fields.csv 0025 fields = textscan(fid,repmat('%s',1,15),'Delimiter','\t','HeaderLines',1); 0026 fields = fields{1}; 0027 fclose(fid); 0028 end 0029 0030 modelfields = fieldnames(model); 0031 order = fields(ismember(fields(:,1),modelfields)); 0032 remainingOrder = sort(setdiff(modelfields,order)); 0033 overallOrder = [columnVector(order);columnVector(remainingOrder)]; 0034 orderedModel = orderfields(model,overallOrder); 0035 end 0036 0037 function vecT = columnVector(vec) 0038 % Converts a vector to a column vector 0039 % 0040 % USAGE: 0041 % 0042 % vecT = columnVector(vec) 0043 % 0044 % INPUT: 0045 % vec: a vector 0046 % 0047 % OUTPUT: 0048 % vecT: a column vector 0049 % 0050 % .. Authors: 0051 % - Original file: Markus Herrgard 0052 % - Minor changes: Laurent Heirendt January 2017 0053 % - Copied from COBRA Toolbox May 2022 0054 0055 [n, m] = size(vec); 0056 0057 if (m ~= 1 && n < m) || n == 1 0058 vecT = vec'; 0059 else 0060 vecT = vec; 0061 end 0062 end