saveECmodel Saves the ecModel in either YAML format (= default and preferred, as all ecModel content is reserved) and/or SBML format (= more widely compatible with other constraint-based modelling tools, can be used for running simulations like FBA etc., but this model cannot be loaded back into MATLAB for applying further GECKO functions, as model.ec is lost). The ecModel is saved to the ecModel-specific models/ subfolder. For saving to other locations, writeYAMLmodel or exportModel are more suitable. Input: ecModel an ecModel in GECKO 3 format (with ecModel.ec structure) filename ending with either .yml or .xml, specifying if the ecModel should be saved in YAML or SBML file format. If no file extension is given, the ecModel will be saved in YAML format. If no filename is given, 'ecModel.yml' is used. modelAdapter a loaded model adapter, from where the model folder is read (Optional, will otherwise use the default model adapter). Usage: saveECmodel(ecModel,filename,modelAdapter)
0001 function saveEcModel(ecModel,filename,modelAdapter) 0002 % saveECmodel 0003 % Saves the ecModel in either YAML format (= default and preferred, as 0004 % all ecModel content is reserved) and/or SBML format (= more widely 0005 % compatible with other constraint-based modelling tools, can be used for 0006 % running simulations like FBA etc., but this model cannot be loaded back 0007 % into MATLAB for applying further GECKO functions, as model.ec is lost). 0008 % 0009 % The ecModel is saved to the ecModel-specific models/ subfolder. For 0010 % saving to other locations, writeYAMLmodel or exportModel are more 0011 % suitable. 0012 % 0013 % Input: 0014 % ecModel an ecModel in GECKO 3 format (with ecModel.ec structure) 0015 % filename ending with either .yml or .xml, specifying if the 0016 % ecModel should be saved in YAML or SBML file format. If 0017 % no file extension is given, the ecModel will be saved 0018 % in YAML format. If no filename is given, 'ecModel.yml' 0019 % is used. 0020 % modelAdapter a loaded model adapter, from where the model folder is 0021 % read (Optional, will otherwise use the default model adapter). 0022 % 0023 % Usage: 0024 % saveECmodel(ecModel,filename,modelAdapter) 0025 0026 0027 if nargin < 3 || isempty(modelAdapter) 0028 modelAdapter = ModelAdapterManager.getDefault(); 0029 if isempty(modelAdapter) 0030 error('Either send in a modelAdapter or set the default model adapter in the ModelAdapterManager.') 0031 end 0032 end 0033 params = modelAdapter.getParameters(); 0034 if nargin < 2 || isempty(filename) 0035 filename = 'ecModel'; 0036 end 0037 filename = fullfile(params.path,'models',filename); 0038 0039 ecModel.description = ['Enzyme-constrained model of ' ecModel.id]; 0040 0041 switch filename(end-3:end) 0042 case {'.xml','sbml'} 0043 exportModel(ecModel, filename); 0044 %Convert notation "e-005" to "e-05 " in stoich. coeffs. to avoid 0045 %inconsistencies between Windows and MAC: 0046 copyfile(filename,'backup.xml') 0047 fin = fopen('backup.xml', 'r'); 0048 fout = fopen(filename, 'w'); 0049 still_reading = true; 0050 while still_reading 0051 inline = fgets(fin); 0052 if ~ischar(inline) 0053 still_reading = false; 0054 else 0055 if ~isempty(regexp(inline,'-00[0-9]','once')) 0056 inline = strrep(inline,'-00','-0'); 0057 elseif ~isempty(regexp(inline,'-01[0-9]','once')) 0058 inline = strrep(inline,'-01','-1'); 0059 end 0060 fwrite(fout, inline); 0061 end 0062 end 0063 fclose('all'); 0064 delete('backup.xml'); 0065 otherwise % Assume YAML 0066 writeYAMLmodel(ecModel,filename); 0067 end 0068 end