0001 function out=exportForGit(model,prefix,path,formats,mainBranchFlag,subDirs,COBRAtext,neverPrefixIDs)
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
0032
0033
0034
0035
0036 if nargin<8
0037 neverPrefixIDs=false;
0038 end
0039 if nargin<7 || isempty(COBRAtext)
0040 COBRAtext=false;
0041 end
0042 if nargin<6 || isempty(subDirs)
0043 subDirs=true;
0044 end
0045 if nargin<5 || isempty(mainBranchFlag)
0046 mainBranchFlag=false;
0047 end
0048 if nargin<4 || isempty(formats)
0049 formats={'mat', 'txt', 'xlsx', 'xml', 'yml'};
0050 else
0051 formats=convertCharArray(formats);
0052 end
0053 if any(~ismember(formats, {'mat', 'txt', 'xlsx', 'xml', 'yml'}))
0054 EM='Unknown file format defined. Only mat, txt, xlsx, xml and yml are allowed file formats.';
0055 error(EM)
0056 end
0057 if nargin<3 || isempty(path)
0058 path='.';
0059 else
0060 path=char(path);
0061 end
0062 if nargin<2 || isempty(prefix)
0063 prefix='model';
0064 else
0065 prefix=char(prefix);
0066 end
0067
0068
0069 model=sortIdentifiers(model);
0070
0071
0072 RAVENver = getToolboxVersion('RAVEN','ravenCobraWrapper.m',mainBranchFlag);
0073 if exist('initCobraToolbox.m','file')
0074 COBRAver = getToolboxVersion('COBRA','initCobraToolbox.m',mainBranchFlag);
0075 end
0076
0077
0078 [ravenDir,prevDir]=findRAVENroot();
0079 try
0080 libSBMLver=OutputSBML_RAVEN;
0081 libSBMLver=libSBMLver.libSBML_version_string;
0082 catch
0083 fid = fopen('tempModelForLibSBMLversion.xml','w+');
0084 fclose(fid);
0085 evalc('[~,~,libSBMLver]=TranslateSBML_RAVEN(''tempModelForLibSBMLversion.xml'',0,0)');
0086 libSBMLver=libSBMLver.libSBML_version_string;
0087 delete('tempModelForLibSBMLversion.xml');
0088 end
0089
0090
0091 if subDirs
0092 path=fullfile(path,'model');
0093 filePath=strcat(path,filesep,{'txt','yml','mat','xlsx','xml'});
0094 [~,~,~]=mkdir(path);
0095 for i = 1:length(formats)
0096 [~,~,~]=mkdir(fullfile(path,formats{i}));
0097 end
0098 else
0099 filePath=cell(1,5); filePath(:)={path};
0100 end
0101
0102
0103
0104 if ismember('txt', formats)
0105 fid=fopen(fullfile(filePath{1},strcat(prefix,'.txt')),'w');
0106 if COBRAtext==true
0107 eqns=constructEquations(model,model.rxns,false,false,false);
0108 eqns=strrep(eqns,' => ',' -> ');
0109 eqns=strrep(eqns,' <=> ',' <=> ');
0110 eqns=regexprep(eqns,'> $','>');
0111 grRules=regexprep(model.grRules,'\((?!\()','( ');
0112 grRules=regexprep(grRules,'(?<!\))\)',' )');
0113 else
0114 eqns=constructEquations(model,model.rxns);
0115 grRules=model.grRules;
0116 end
0117 fprintf(fid, 'Rxn name\tFormula\tGene-reaction association\tLB\tUB\tObjective\n');
0118 for i = 1:numel(model.rxns)
0119 fprintf(fid, '%s\t', model.rxns{i});
0120 fprintf(fid, '%s \t', eqns{i});
0121 fprintf(fid, '%s\t', grRules{i});
0122 fprintf(fid, '%6.2f\t%6.2f\t%6.2f\n', model.lb(i), model.ub(i), model.c(i));
0123 end
0124 fclose(fid);
0125 end
0126
0127
0128 if ismember('yml', formats)
0129 writeYAMLmodel(model,fullfile(filePath{2},strcat(prefix,'.yml')));
0130 end
0131
0132
0133 if ismember('mat', formats)
0134 save(fullfile(filePath{3},strcat(prefix,'.mat')),'model');
0135 end
0136
0137
0138 if ismember('xlsx', formats)
0139 exportToExcelFormat(model,fullfile(filePath{4},strcat(prefix,'.xlsx')));
0140 end
0141
0142
0143 if ismember('xml', formats)
0144 exportModel(model,fullfile(filePath{5},strcat(prefix,'.xml')),neverPrefixIDs);
0145 end
0146
0147
0148 fid = fopen(fullfile(path,'dependencies.txt'),'wt');
0149 fprintf(fid,['MATLAB\t' version '\n']);
0150 fprintf(fid,['libSBML\t' libSBMLver '\n']);
0151 fprintf(fid,['RAVEN_toolbox\t' RAVENver '\n']);
0152 if ~isempty(COBRAver)
0153 fprintf(fid,['COBRA_toolbox\t' COBRAver '\n']);
0154 end
0155 if isfield(model,'modelVersion')
0156 fields = fieldnames(model.modelVersion);
0157 for i = 1:length(fields)
0158 value = model.modelVersion.(fields{i});
0159 fprintf(fid,[fields{i} '\t' num2str(value) '\n']);
0160 end
0161 end
0162 fclose(fid);
0163 end