diff --git a/core/permuteModel.m b/core/permuteModel.m index 15765f83..23a06cea 100755 --- a/core/permuteModel.m +++ b/core/permuteModel.m @@ -2,111 +2,155 @@ % permuteModel % Changes the order of the reactions or metabolites in a model % +% Input: % model a model structure -% indexes a vector with the same length as the number of reactions in the -% model which gives the new order of reactions -% type 'rxns' for reactions and 'mets' for metabolites +% indexes a vector with the same length as the number of items in the +% model, which gives the new order of items +% type 'rxns' for reactions, 'mets' for metabolites, 'genes' for +% genes, 'comps' for compartments % -% newModel an updated model structure +% Output: +% newModel an updated model structure % % Usage: newModel=permuteModel(model, indexes, type) newModel=model; indexes=indexes(:); -if strcmp(type,'rxns') - if isfield(newModel,'rxns') - newModel.rxns=newModel.rxns(indexes); - end - if isfield(newModel,'lb') - newModel.lb=newModel.lb(indexes); - end - if isfield(newModel,'ub') - newModel.ub=newModel.ub(indexes); - end - if isfield(newModel,'rev') - newModel.rev=newModel.rev(indexes); - end - if isfield(newModel,'c') - newModel.c=newModel.c(indexes); - end - if isfield(newModel,'S') - newModel.S=newModel.S(:,indexes); - end - if isfield(newModel,'rxnNames') - newModel.rxnNames=newModel.rxnNames(indexes); - end - if isfield(newModel,'rxnGeneMat') - newModel.rxnGeneMat=newModel.rxnGeneMat(indexes,:); - end - if isfield(newModel,'grRules') - newModel.grRules=newModel.grRules(indexes); - end - if isfield(newModel,'subSystems') - newModel.subSystems=newModel.subSystems(indexes); - end - if isfield(newModel,'eccodes') - newModel.eccodes=newModel.eccodes(indexes); - end - if isfield(newModel,'equations') - newModel.equations=newModel.equations(indexes); - end - if isfield(newModel,'rxnMiriams') - newModel.rxnMiriams=newModel.rxnMiriams(indexes); - end - if isfield(newModel,'rxnComps') - newModel.rxnComps=newModel.rxnComps(indexes); - end - if isfield(newModel,'rxnFrom') - newModel.rxnFrom=newModel.rxnFrom(indexes); - end - if isfield(newModel,'rxnScores') - newModel.rxnScores=newModel.rxnScores(indexes); - end - if isfield(newModel,'rxnNotes') - newModel.rxnNotes=newModel.rxnNotes(indexes); - end - if isfield(newModel,'rxnReferences') - newModel.rxnReferences=newModel.rxnReferences(indexes); - end - if isfield(newModel,'rxnConfidenceScores') - newModel.rxnConfidenceScores=newModel.rxnConfidenceScores(indexes); - end -end - -if strcmp(type,'mets') - if isfield(newModel,'mets') - newModel.mets=newModel.mets(indexes); - end - if isfield(newModel,'metNames') - newModel.metNames=newModel.metNames(indexes); - end - if isfield(newModel,'b') - newModel.b=newModel.b(indexes,:); - end - if isfield(newModel,'metComps') - newModel.metComps=newModel.metComps(indexes); - end - if isfield(newModel,'S') - newModel.S=newModel.S(indexes,:); - end - if isfield(newModel,'unconstrained') - newModel.unconstrained=newModel.unconstrained(indexes); - end - if isfield(newModel,'metMiriams') - newModel.metMiriams=newModel.metMiriams(indexes,:); - end - if isfield(newModel,'inchis') - newModel.inchis=newModel.inchis(indexes); - end - if isfield(newModel,'metFormulas') - newModel.metFormulas=newModel.metFormulas(indexes); - end - if isfield(newModel,'metFrom') - newModel.metFrom=newModel.metFrom(indexes); - end - if isfield(newModel,'metCharges') - newModel.metCharges=newModel.metCharges(indexes); - end +switch type + case 'rxns' + if isfield(newModel,'rxns') + newModel.rxns=newModel.rxns(indexes); + end + if isfield(newModel,'lb') + newModel.lb=newModel.lb(indexes); + end + if isfield(newModel,'ub') + newModel.ub=newModel.ub(indexes); + end + if isfield(newModel,'rev') + newModel.rev=newModel.rev(indexes); + end + if isfield(newModel,'c') + newModel.c=newModel.c(indexes); + end + if isfield(newModel,'S') + newModel.S=newModel.S(:,indexes); + end + if isfield(newModel,'rxnNames') + newModel.rxnNames=newModel.rxnNames(indexes); + end + if isfield(newModel,'rxnGeneMat') + newModel.rxnGeneMat=newModel.rxnGeneMat(indexes,:); + end + if isfield(newModel,'grRules') + newModel.grRules=newModel.grRules(indexes); + end + if isfield(newModel,'subSystems') + newModel.subSystems=newModel.subSystems(indexes); + end + if isfield(newModel,'eccodes') + newModel.eccodes=newModel.eccodes(indexes); + end + if isfield(newModel,'equations') + newModel.equations=newModel.equations(indexes); + end + if isfield(newModel,'rxnMiriams') + newModel.rxnMiriams=newModel.rxnMiriams(indexes); + end + if isfield(newModel,'rxnComps') + newModel.rxnComps=newModel.rxnComps(indexes); + end + if isfield(newModel,'rxnFrom') + newModel.rxnFrom=newModel.rxnFrom(indexes); + end + if isfield(newModel,'rxnScores') + newModel.rxnScores=newModel.rxnScores(indexes); + end + if isfield(newModel,'rxnNotes') + newModel.rxnNotes=newModel.rxnNotes(indexes); + end + if isfield(newModel,'rxnReferences') + newModel.rxnReferences=newModel.rxnReferences(indexes); + end + if isfield(newModel,'rxnConfidenceScores') + newModel.rxnConfidenceScores=newModel.rxnConfidenceScores(indexes); + end + case 'mets' + if isfield(newModel,'mets') + newModel.mets=newModel.mets(indexes); + end + if isfield(newModel,'metNames') + newModel.metNames=newModel.metNames(indexes); + end + if isfield(newModel,'b') + newModel.b=newModel.b(indexes,:); + end + if isfield(newModel,'metComps') + newModel.metComps=newModel.metComps(indexes); + end + if isfield(newModel,'S') + newModel.S=newModel.S(indexes,:); + end + if isfield(newModel,'unconstrained') + newModel.unconstrained=newModel.unconstrained(indexes); + end + if isfield(newModel,'metMiriams') + newModel.metMiriams=newModel.metMiriams(indexes,:); + end + if isfield(newModel,'inchis') + newModel.inchis=newModel.inchis(indexes); + end + if isfield(newModel,'metFormulas') + newModel.metFormulas=newModel.metFormulas(indexes); + end + if isfield(newModel,'metFrom') + newModel.metFrom=newModel.metFrom(indexes); + end + if isfield(newModel,'metCharges') + newModel.metCharges=newModel.metCharges(indexes); + end + case 'genes' + if isfield(newModel,'genes') + newModel.genes=newModel.genes(indexes); + end + if isfield(newModel,'geneComps') + newModel.geneComps=newModel.geneComps(indexes); + end + if isfield(newModel,'geneMiriams') + newModel.geneMiriams=newModel.geneMiriams(indexes); + end + if isfield(newModel,'geneShortNames') + newModel.geneShortNames=newModel.geneShortNames(indexes); + end + if isfield(newModel,'rxnGeneMat') + newModel.rxnGeneMat=newModel.rxnGeneMat(:,indexes); + end + case 'comps' + if isfield(newModel,'comps') + newModel.comps=newModel.comps(indexes); + end + if isfield(newModel,'compNames') + newModel.compNames=newModel.compNames(indexes); + end + if isfield(newModel,'compOutside') + newModel.compOutside=newModel.compOutside(indexes); + end + if isfield(newModel,'compMiriams') + newModel.compMiriams=newModel.compMiriams(indexes); + end + [~,J]=sort(indexes); % The *index* of compartment is used in next fields + if isfield(newModel,'metComps') + [toreplace, bywhat] = ismember(newModel.metComps,1:length(J)); + newModel.metComps(toreplace) = J(bywhat(toreplace)); + end + if isfield(model,'rxnComps') + [toreplace, bywhat] = ismember(model.rxnComps,1:length(J)); + model.rxnComps(toreplace) = J(bywhat(toreplace)); + end + if isfield(model,'geneComps') + [toreplace, bywhat] = ismember(model.geneComps,1:length(J)); + model.geneComps(toreplace) = J(bywhat(toreplace)); + end end end diff --git a/doc/core/permuteModel.html b/doc/core/permuteModel.html index e09feed4..32b608e1 100644 --- a/doc/core/permuteModel.html +++ b/doc/core/permuteModel.html @@ -30,12 +30,15 @@

DESCRIPTION ^
 permuteModel
    Changes the order of the reactions or metabolites in a model
 
+   Input:
    model     a model structure
-   indexes   a vector with the same length as the number of reactions in the
-             model which gives the new order of reactions
-   type      'rxns' for reactions and 'mets' for metabolites
+   indexes   a vector with the same length as the number of items in the
+             model, which gives the new order of items
+   type      'rxns' for reactions, 'mets' for metabolites, 'genes' for
+             genes, 'comps' for compartments
 
-     newModel  an updated model structure
+     Output:
+   newModel  an updated model structure
 
      Usage: newModel=permuteModel(model, indexes, type)
@@ -56,114 +59,158 @@

SOURCE CODE ^% permuteModel 0003 % Changes the order of the reactions or metabolites in a model 0004 % -0005 % model a model structure -0006 % indexes a vector with the same length as the number of reactions in the -0007 % model which gives the new order of reactions -0008 % type 'rxns' for reactions and 'mets' for metabolites -0009 % -0010 % newModel an updated model structure +0005 % Input: +0006 % model a model structure +0007 % indexes a vector with the same length as the number of items in the +0008 % model, which gives the new order of items +0009 % type 'rxns' for reactions, 'mets' for metabolites, 'genes' for +0010 % genes, 'comps' for compartments 0011 % -0012 % Usage: newModel=permuteModel(model, indexes, type) -0013 -0014 newModel=model; -0015 indexes=indexes(:); +0012 % Output: +0013 % newModel an updated model structure +0014 % +0015 % Usage: newModel=permuteModel(model, indexes, type) 0016 -0017 if strcmp(type,'rxns') -0018 if isfield(newModel,'rxns') -0019 newModel.rxns=newModel.rxns(indexes); -0020 end -0021 if isfield(newModel,'lb') -0022 newModel.lb=newModel.lb(indexes); -0023 end -0024 if isfield(newModel,'ub') -0025 newModel.ub=newModel.ub(indexes); -0026 end -0027 if isfield(newModel,'rev') -0028 newModel.rev=newModel.rev(indexes); -0029 end -0030 if isfield(newModel,'c') -0031 newModel.c=newModel.c(indexes); -0032 end -0033 if isfield(newModel,'S') -0034 newModel.S=newModel.S(:,indexes); -0035 end -0036 if isfield(newModel,'rxnNames') -0037 newModel.rxnNames=newModel.rxnNames(indexes); -0038 end -0039 if isfield(newModel,'rxnGeneMat') -0040 newModel.rxnGeneMat=newModel.rxnGeneMat(indexes,:); -0041 end -0042 if isfield(newModel,'grRules') -0043 newModel.grRules=newModel.grRules(indexes); -0044 end -0045 if isfield(newModel,'subSystems') -0046 newModel.subSystems=newModel.subSystems(indexes); -0047 end -0048 if isfield(newModel,'eccodes') -0049 newModel.eccodes=newModel.eccodes(indexes); -0050 end -0051 if isfield(newModel,'equations') -0052 newModel.equations=newModel.equations(indexes); -0053 end -0054 if isfield(newModel,'rxnMiriams') -0055 newModel.rxnMiriams=newModel.rxnMiriams(indexes); -0056 end -0057 if isfield(newModel,'rxnComps') -0058 newModel.rxnComps=newModel.rxnComps(indexes); -0059 end -0060 if isfield(newModel,'rxnFrom') -0061 newModel.rxnFrom=newModel.rxnFrom(indexes); -0062 end -0063 if isfield(newModel,'rxnScores') -0064 newModel.rxnScores=newModel.rxnScores(indexes); -0065 end -0066 if isfield(newModel,'rxnNotes') -0067 newModel.rxnNotes=newModel.rxnNotes(indexes); -0068 end -0069 if isfield(newModel,'rxnReferences') -0070 newModel.rxnReferences=newModel.rxnReferences(indexes); -0071 end -0072 if isfield(newModel,'rxnConfidenceScores') -0073 newModel.rxnConfidenceScores=newModel.rxnConfidenceScores(indexes); -0074 end -0075 end -0076 -0077 if strcmp(type,'mets') -0078 if isfield(newModel,'mets') -0079 newModel.mets=newModel.mets(indexes); -0080 end -0081 if isfield(newModel,'metNames') -0082 newModel.metNames=newModel.metNames(indexes); -0083 end -0084 if isfield(newModel,'b') -0085 newModel.b=newModel.b(indexes,:); -0086 end -0087 if isfield(newModel,'metComps') -0088 newModel.metComps=newModel.metComps(indexes); -0089 end -0090 if isfield(newModel,'S') -0091 newModel.S=newModel.S(indexes,:); -0092 end -0093 if isfield(newModel,'unconstrained') -0094 newModel.unconstrained=newModel.unconstrained(indexes); -0095 end -0096 if isfield(newModel,'metMiriams') -0097 newModel.metMiriams=newModel.metMiriams(indexes,:); -0098 end -0099 if isfield(newModel,'inchis') -0100 newModel.inchis=newModel.inchis(indexes); -0101 end -0102 if isfield(newModel,'metFormulas') -0103 newModel.metFormulas=newModel.metFormulas(indexes); -0104 end -0105 if isfield(newModel,'metFrom') -0106 newModel.metFrom=newModel.metFrom(indexes); -0107 end -0108 if isfield(newModel,'metCharges') -0109 newModel.metCharges=newModel.metCharges(indexes); -0110 end -0111 end -0112 end +0017 newModel=model; +0018 indexes=indexes(:); +0019 +0020 switch type +0021 case 'rxns' +0022 if isfield(newModel,'rxns') +0023 newModel.rxns=newModel.rxns(indexes); +0024 end +0025 if isfield(newModel,'lb') +0026 newModel.lb=newModel.lb(indexes); +0027 end +0028 if isfield(newModel,'ub') +0029 newModel.ub=newModel.ub(indexes); +0030 end +0031 if isfield(newModel,'rev') +0032 newModel.rev=newModel.rev(indexes); +0033 end +0034 if isfield(newModel,'c') +0035 newModel.c=newModel.c(indexes); +0036 end +0037 if isfield(newModel,'S') +0038 newModel.S=newModel.S(:,indexes); +0039 end +0040 if isfield(newModel,'rxnNames') +0041 newModel.rxnNames=newModel.rxnNames(indexes); +0042 end +0043 if isfield(newModel,'rxnGeneMat') +0044 newModel.rxnGeneMat=newModel.rxnGeneMat(indexes,:); +0045 end +0046 if isfield(newModel,'grRules') +0047 newModel.grRules=newModel.grRules(indexes); +0048 end +0049 if isfield(newModel,'subSystems') +0050 newModel.subSystems=newModel.subSystems(indexes); +0051 end +0052 if isfield(newModel,'eccodes') +0053 newModel.eccodes=newModel.eccodes(indexes); +0054 end +0055 if isfield(newModel,'equations') +0056 newModel.equations=newModel.equations(indexes); +0057 end +0058 if isfield(newModel,'rxnMiriams') +0059 newModel.rxnMiriams=newModel.rxnMiriams(indexes); +0060 end +0061 if isfield(newModel,'rxnComps') +0062 newModel.rxnComps=newModel.rxnComps(indexes); +0063 end +0064 if isfield(newModel,'rxnFrom') +0065 newModel.rxnFrom=newModel.rxnFrom(indexes); +0066 end +0067 if isfield(newModel,'rxnScores') +0068 newModel.rxnScores=newModel.rxnScores(indexes); +0069 end +0070 if isfield(newModel,'rxnNotes') +0071 newModel.rxnNotes=newModel.rxnNotes(indexes); +0072 end +0073 if isfield(newModel,'rxnReferences') +0074 newModel.rxnReferences=newModel.rxnReferences(indexes); +0075 end +0076 if isfield(newModel,'rxnConfidenceScores') +0077 newModel.rxnConfidenceScores=newModel.rxnConfidenceScores(indexes); +0078 end +0079 case 'mets' +0080 if isfield(newModel,'mets') +0081 newModel.mets=newModel.mets(indexes); +0082 end +0083 if isfield(newModel,'metNames') +0084 newModel.metNames=newModel.metNames(indexes); +0085 end +0086 if isfield(newModel,'b') +0087 newModel.b=newModel.b(indexes,:); +0088 end +0089 if isfield(newModel,'metComps') +0090 newModel.metComps=newModel.metComps(indexes); +0091 end +0092 if isfield(newModel,'S') +0093 newModel.S=newModel.S(indexes,:); +0094 end +0095 if isfield(newModel,'unconstrained') +0096 newModel.unconstrained=newModel.unconstrained(indexes); +0097 end +0098 if isfield(newModel,'metMiriams') +0099 newModel.metMiriams=newModel.metMiriams(indexes,:); +0100 end +0101 if isfield(newModel,'inchis') +0102 newModel.inchis=newModel.inchis(indexes); +0103 end +0104 if isfield(newModel,'metFormulas') +0105 newModel.metFormulas=newModel.metFormulas(indexes); +0106 end +0107 if isfield(newModel,'metFrom') +0108 newModel.metFrom=newModel.metFrom(indexes); +0109 end +0110 if isfield(newModel,'metCharges') +0111 newModel.metCharges=newModel.metCharges(indexes); +0112 end +0113 case 'genes' +0114 if isfield(newModel,'genes') +0115 newModel.genes=newModel.genes(indexes); +0116 end +0117 if isfield(newModel,'geneComps') +0118 newModel.geneComps=newModel.geneComps(indexes); +0119 end +0120 if isfield(newModel,'geneMiriams') +0121 newModel.geneMiriams=newModel.geneMiriams(indexes); +0122 end +0123 if isfield(newModel,'geneShortNames') +0124 newModel.geneShortNames=newModel.geneShortNames(indexes); +0125 end +0126 if isfield(newModel,'rxnGeneMat') +0127 newModel.rxnGeneMat=newModel.rxnGeneMat(:,indexes); +0128 end +0129 case 'comps' +0130 if isfield(newModel,'comps') +0131 newModel.comps=newModel.comps(indexes); +0132 end +0133 if isfield(newModel,'compNames') +0134 newModel.compNames=newModel.compNames(indexes); +0135 end +0136 if isfield(newModel,'compOutside') +0137 newModel.compOutside=newModel.compOutside(indexes); +0138 end +0139 if isfield(newModel,'compMiriams') +0140 newModel.compMiriams=newModel.compMiriams(indexes); +0141 end +0142 [~,J]=sort(indexes); % The *index* of compartment is used in next fields +0143 if isfield(newModel,'metComps') +0144 [toreplace, bywhat] = ismember(newModel.metComps,1:length(J)); +0145 newModel.metComps(toreplace) = J(bywhat(toreplace)); +0146 end +0147 if isfield(model,'rxnComps') +0148 [toreplace, bywhat] = ismember(model.rxnComps,1:length(J)); +0149 model.rxnComps(toreplace) = J(bywhat(toreplace)); +0150 end +0151 if isfield(model,'geneComps') +0152 [toreplace, bywhat] = ismember(model.geneComps,1:length(J)); +0153 model.geneComps(toreplace) = J(bywhat(toreplace)); +0154 end +0155 end +0156 end
Generated by m2html © 2005
\ No newline at end of file diff --git a/doc/io/SBMLFromExcel.html b/doc/io/SBMLFromExcel.html index 9799b702..34b74dae 100644 --- a/doc/io/SBMLFromExcel.html +++ b/doc/io/SBMLFromExcel.html @@ -49,7 +49,7 @@

DESCRIPTION ^CROSS-REFERENCE INFORMATION ^

This function calls: +
  • exportModel exportModel
  • importExcelModel importExcelModel
  • This function is called by: @@ -86,7 +86,7 @@

    SOURCE CODE ^importExcelModel(fileName,false,printWarnings); 0028 printModelStats(model,printWarnings,false); -0029 exportModel(model,outputFileName,toCOBRA,true); +0029 exportModel(model,outputFileName,toCOBRA,true); 0030 end
    Generated by m2html © 2005
    diff --git a/doc/io/exportForGit.html b/doc/io/exportForGit.html index 82d9dc3b..a7418a09 100644 --- a/doc/io/exportForGit.html +++ b/doc/io/exportForGit.html @@ -56,7 +56,7 @@

    DESCRIPTION ^CROSS-REFERENCE INFORMATION ^

    This function calls: +
  • exportModel exportModel
  • exportToExcelFormat exportToExcelFormat
  • getToolboxVersion getToolboxVersion
  • sortIdentifiers exportModel
  • writeYaml writeYaml
  • This function is called by: @@ -113,91 +113,94 @@

    SOURCE CODE ^'model'; 0047 end 0048 -0049 %Get versions or commits of toolboxes: -0050 RAVENver = getToolboxVersion('RAVEN','ravenCobraWrapper.m',masterFlag); -0051 COBRAver = getToolboxVersion('COBRA','initCobraToolbox.m',masterFlag); -0052 -0053 %Retrieve libSBML version: -0054 try % 5.17.0 and newer -0055 libSBMLver=OutputSBML; -0056 libSBMLver=libSBMLver.libSBML_version_string; -0057 catch % before 5.17.0 -0058 fid = fopen('tempModelForLibSBMLversion.xml','w+'); -0059 fclose(fid); -0060 evalc('[~,~,libSBMLver]=TranslateSBML(''tempModelForLibSBMLversion.xml'',0,0)'); -0061 libSBMLver=libSBMLver.libSBML_version_string; -0062 delete('tempModelForLibSBMLversion.xml'); -0063 end -0064 -0065 % Make models folder, no warnings if folder already exists -0066 if subDirs -0067 path=fullfile(path,'model'); -0068 filePath=strcat(path,filesep,{'txt','yml','mat','xlsx','xml'}); -0069 [~,~,~]=mkdir(path); -0070 for i = 1:length(formats) -0071 [~,~,~]=mkdir(fullfile(path,formats{i})); -0072 end -0073 else -0074 filePath=cell(1,5); filePath(:)={path}; -0075 end -0076 -0077 -0078 % Write TXT format -0079 if ismember('txt', formats) -0080 fid=fopen(fullfile(filePath{1},strcat(prefix,'.txt')),'w'); -0081 eqns=constructEquations(model,model.rxns,false,false,false,true); -0082 eqns=strrep(eqns,' => ',' -> '); -0083 eqns=strrep(eqns,' <=> ',' <=> '); -0084 eqns=regexprep(eqns,'> $','>'); -0085 grRules=regexprep(model.grRules,'\((?!\()','( '); -0086 grRules=regexprep(grRules,'(?<!\))\)',' )'); -0087 fprintf(fid, 'Rxn name\tFormula\tGene-reaction association\tLB\tUB\tObjective\n'); -0088 for i = 1:numel(model.rxns) -0089 fprintf(fid, '%s\t', model.rxns{i}); -0090 fprintf(fid, '%s \t', eqns{i}); -0091 fprintf(fid, '%s\t', grRules{i}); -0092 fprintf(fid, '%6.2f\t%6.2f\t%6.2f\n', model.lb(i), model.ub(i), model.c(i)); -0093 end -0094 fclose(fid); -0095 end -0096 -0097 % Write YML format -0098 if ismember('yml', formats) -0099 writeYaml(model,fullfile(filePath{2},strcat(prefix,'.yml'))); -0100 end -0101 -0102 % Write MAT format -0103 if ismember('mat', formats) -0104 save(fullfile(filePath{3},strcat(prefix,'.mat')),'model'); -0105 end -0106 -0107 % Write XLSX format -0108 if ismember('xlsx', formats) -0109 exportToExcelFormat(model,fullfile(filePath{4},strcat(prefix,'.xlsx'))); -0110 end -0111 -0112 % Write XML format -0113 if ismember('xml', formats) -0114 exportModel(model,fullfile(filePath{5},strcat(prefix,'.xml'))); -0115 end -0116 -0117 %Save file with versions: -0118 fid = fopen(fullfile(path,'dependencies.txt'),'wt'); -0119 fprintf(fid,['MATLAB\t' version '\n']); -0120 fprintf(fid,['libSBML\t' libSBMLver '\n']); -0121 fprintf(fid,['RAVEN_toolbox\t' RAVENver '\n']); -0122 if ~isempty(COBRAver) -0123 fprintf(fid,['COBRA_toolbox\t' COBRAver '\n']); -0124 end -0125 if isfield(model,'modelVersion') -0126 fields = fieldnames(model.modelVersion); -0127 for i = 1:length(fields) -0128 value = model.modelVersion.(fields{i}); -0129 fprintf(fid,[fields{i} '\t' num2str(value) '\n']); -0130 end -0131 end -0132 fclose(fid); -0133 end +0049 %Sort reactions, metabolites and genes alphabetically +0050 model=sortIdentifiers(model); +0051 +0052 %Get versions or commits of toolboxes: +0053 RAVENver = getToolboxVersion('RAVEN','ravenCobraWrapper.m',masterFlag); +0054 COBRAver = getToolboxVersion('COBRA','initCobraToolbox.m',masterFlag); +0055 +0056 %Retrieve libSBML version: +0057 try % 5.17.0 and newer +0058 libSBMLver=OutputSBML; +0059 libSBMLver=libSBMLver.libSBML_version_string; +0060 catch % before 5.17.0 +0061 fid = fopen('tempModelForLibSBMLversion.xml','w+'); +0062 fclose(fid); +0063 evalc('[~,~,libSBMLver]=TranslateSBML(''tempModelForLibSBMLversion.xml'',0,0)'); +0064 libSBMLver=libSBMLver.libSBML_version_string; +0065 delete('tempModelForLibSBMLversion.xml'); +0066 end +0067 +0068 % Make models folder, no warnings if folder already exists +0069 if subDirs +0070 path=fullfile(path,'model'); +0071 filePath=strcat(path,filesep,{'txt','yml','mat','xlsx','xml'}); +0072 [~,~,~]=mkdir(path); +0073 for i = 1:length(formats) +0074 [~,~,~]=mkdir(fullfile(path,formats{i})); +0075 end +0076 else +0077 filePath=cell(1,5); filePath(:)={path}; +0078 end +0079 +0080 +0081 % Write TXT format +0082 if ismember('txt', formats) +0083 fid=fopen(fullfile(filePath{1},strcat(prefix,'.txt')),'w'); +0084 eqns=constructEquations(model,model.rxns,false,false,false,true); +0085 eqns=strrep(eqns,' => ',' -> '); +0086 eqns=strrep(eqns,' <=> ',' <=> '); +0087 eqns=regexprep(eqns,'> $','>'); +0088 grRules=regexprep(model.grRules,'\((?!\()','( '); +0089 grRules=regexprep(grRules,'(?<!\))\)',' )'); +0090 fprintf(fid, 'Rxn name\tFormula\tGene-reaction association\tLB\tUB\tObjective\n'); +0091 for i = 1:numel(model.rxns) +0092 fprintf(fid, '%s\t', model.rxns{i}); +0093 fprintf(fid, '%s \t', eqns{i}); +0094 fprintf(fid, '%s\t', grRules{i}); +0095 fprintf(fid, '%6.2f\t%6.2f\t%6.2f\n', model.lb(i), model.ub(i), model.c(i)); +0096 end +0097 fclose(fid); +0098 end +0099 +0100 % Write YML format +0101 if ismember('yml', formats) +0102 writeYaml(model,fullfile(filePath{2},strcat(prefix,'.yml'))); +0103 end +0104 +0105 % Write MAT format +0106 if ismember('mat', formats) +0107 save(fullfile(filePath{3},strcat(prefix,'.mat')),'model'); +0108 end +0109 +0110 % Write XLSX format +0111 if ismember('xlsx', formats) +0112 exportToExcelFormat(model,fullfile(filePath{4},strcat(prefix,'.xlsx'))); +0113 end +0114 +0115 % Write XML format +0116 if ismember('xml', formats) +0117 exportModel(model,fullfile(filePath{5},strcat(prefix,'.xml'))); +0118 end +0119 +0120 %Save file with versions: +0121 fid = fopen(fullfile(path,'dependencies.txt'),'wt'); +0122 fprintf(fid,['MATLAB\t' version '\n']); +0123 fprintf(fid,['libSBML\t' libSBMLver '\n']); +0124 fprintf(fid,['RAVEN_toolbox\t' RAVENver '\n']); +0125 if ~isempty(COBRAver) +0126 fprintf(fid,['COBRA_toolbox\t' COBRAver '\n']); +0127 end +0128 if isfield(model,'modelVersion') +0129 fields = fieldnames(model.modelVersion); +0130 for i = 1:length(fields) +0131 value = model.modelVersion.(fields{i}); +0132 fprintf(fid,[fields{i} '\t' num2str(value) '\n']); +0133 end +0134 end +0135 fclose(fid); +0136 end
    Generated by m2html © 2005
    \ No newline at end of file diff --git a/doc/io/exportModel.html b/doc/io/exportModel.html index b4ee2aaf..e44d0db7 100644 --- a/doc/io/exportModel.html +++ b/doc/io/exportModel.html @@ -24,7 +24,7 @@

    PURPOSE ^exportModel

    SYNOPSIS ^

    -
    function exportModel(model,fileName,exportGeneComplexes,supressWarnings)
    +
    function exportModel(model,fileName,exportGeneComplexes,supressWarnings,sortIds)

    DESCRIPTION ^

     exportModel
    @@ -38,15 +38,17 @@ 

    DESCRIPTION ^CROSS-REFERENCE INFORMATION ^

    This function calls: +
  • sortIdentifiers exportModel
  • This function is called by: @@ -57,7 +59,7 @@

    SUBFUNCTIONS ^function modelSBML=getSBMLStructure(sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions)
  • function miriamString=getMiriam(miriamStruct)
  • function [tmp_Rxn]=addReactantsProducts(model,sbmlModel,i)
  • function vecT = columnVector(vec)
  • SOURCE CODE ^

    -
    0001 function exportModel(model,fileName,exportGeneComplexes,supressWarnings)
    +
    0001 function exportModel(model,fileName,exportGeneComplexes,supressWarnings,sortIds)
     0002 % exportModel
     0003 %   Exports a constraint-based model to an SBML file (L3V1 FBCv2)
     0004 %
    @@ -69,795 +71,803 @@ 

    SOURCE CODE ^% (opt, default false) 0011 % supressWarnings true if warnings should be supressed (opt, default 0012 % false) -0013 % -0014 % -0015 % Usage: exportModel(model,fileName,exportGeneComplexes,supressWarnings) -0016 if nargin<3 -0017 exportGeneComplexes=false; -0018 end -0019 if nargin<4 -0020 supressWarnings=false; -0021 end -0022 -0023 %If no subSystems are defined, then no need to use groups package -0024 if isfield(model,'subSystems') -0025 modelHasSubsystems=true; -0026 else -0027 modelHasSubsystems=false; -0028 end -0029 -0030 %The default SBML format settings, which are used as input for appropriate -0031 %libSBML functions to generate the blank SBML model structure before using -0032 %exporting in with OutputSBML to xml file -0033 sbmlLevel=3; -0034 sbmlVersion=1; -0035 sbmlPackages={'fbc'}; -0036 sbmlPackageVersions=2; -0037 if modelHasSubsystems -0038 sbmlPackages={sbmlPackages,'groups'}; -0039 sbmlPackageVersions=[sbmlPackageVersions,1]; -0040 end -0041 -0042 %Check if the "unconstrained" field is still present. This shows if -0043 %exchange metabolites have been removed -0044 if ~isfield(model,'unconstrained') -0045 if supressWarnings==false -0046 EM='There is no unconstrained field in the model structure. This means that no metabolites are considered exchange metabolites'; -0047 dispEM(EM,false); -0048 end -0049 model.unconstrained=zeros(numel(model.mets),1); -0050 end -0051 -0052 %If model id and name do not exist, make sure that default -0053 %strings are included -0054 if ~isfield(model,'id') -0055 fprintf('WARNING: The model is missing the "id" field. Uses "blankID". \n'); -0056 model.id='blankID'; -0057 end -0058 if ~isfield(model,'name') -0059 fprintf('WARNING: The model is missing the "name" field. Uses "blankName". \n'); -0060 model.name='blankName'; -0061 end -0062 -0063 %Check the model structure -0064 if supressWarnings==false -0065 checkModelStruct(model,false); -0066 end -0067 -0068 %Add several blank fields, if they do not exist already. This is to reduce -0069 %the number of conditions below -0070 if ~isfield(model,'compMiriams') -0071 model.compMiriams=cell(numel(model.comps),1); -0072 end -0073 if ~isfield(model,'inchis') -0074 model.inchis=cell(numel(model.mets),1); -0075 end -0076 if ~isfield(model,'metFormulas') -0077 model.metFormulas=cell(numel(model.mets),1); -0078 end -0079 if ~isfield(model,'metMiriams') -0080 model.metMiriams=cell(numel(model.mets),1); -0081 end -0082 if ~isfield(model,'geneMiriams') && isfield(model,'genes') -0083 model.geneMiriams=cell(numel(model.genes),1); -0084 end -0085 if ~isfield(model,'geneShortNames') && isfield(model,'genes') -0086 model.geneShortNames=cell(numel(model.genes),1); -0087 end -0088 if ~isfield(model,'subSystems') -0089 model.subSystems=cell(numel(model.rxns),1); -0090 end -0091 if ~isfield(model,'eccodes') -0092 model.eccodes=cell(numel(model.rxns),1); -0093 end -0094 if ~isfield(model,'rxnReferences') -0095 model.rxnReferences=cell(numel(model.rxns),1); -0096 end -0097 if ~isfield(model,'rxnConfidenceScores') -0098 model.rxnConfidenceScores=NaN(numel(model.rxns),1); -0099 end -0100 if ~isfield(model,'rxnNotes') -0101 model.rxnNotes=cell(numel(model.rxns),1); -0102 end -0103 if ~isfield(model,'rxnMiriams') -0104 model.rxnMiriams=cell(numel(model.rxns),1); -0105 end -0106 -0107 if sbmlLevel<3 -0108 %Check if genes have associated compartments -0109 if ~isfield(model,'geneComps') && isfield(model,'genes') -0110 if supressWarnings==false -0111 EM='There are no compartments specified for genes. All genes will be assigned to the first compartment. This is because the SBML structure requires all elements to be assigned to a compartment'; -0112 dispEM(EM,false); -0113 end -0114 model.geneComps=ones(numel(model.genes),1); -0115 end -0116 end -0117 -0118 %Convert ids to SBML-convenient format. This is to avoid the data loss when -0119 %unsupported characters are included in ids. Here we are using part from -0120 %convertSBMLID, originating from the COBRA Toolbox -0121 model.rxns=regexprep(model.rxns,'([^0-9_a-zA-Z])','__${num2str($1+0)}__'); -0122 model.mets=regexprep(model.mets,'([^0-9_a-zA-Z])','__${num2str($1+0)}__'); -0123 model.comps=regexprep(model.comps,'([^0-9_a-zA-Z])','__${num2str($1+0)}__'); -0124 if isfield(model,'genes') -0125 problemGenes=find(~cellfun('isempty',regexp(model.genes,'([^0-9_a-zA-Z])'))); -0126 originalGenes=model.genes(problemGenes); -0127 replacedGenes=regexprep(model.genes(problemGenes),'([^0-9_a-zA-Z])','__${num2str($1+0)}__'); -0128 model.genes(problemGenes)=replacedGenes; -0129 for i=1:numel(problemGenes) -0130 model.grRules = regexprep(model.grRules, ['(^|\s|\()' originalGenes{i} '($|\s|\))'], ['$1' replacedGenes{i} '$2']); -0131 end -0132 end -0133 -0134 %Generate an empty SBML structure -0135 modelSBML=getSBMLStructure(sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0136 modelSBML.metaid=model.id; -0137 modelSBML.id=model.id; -0138 modelSBML.name=model.name; -0139 -0140 if isfield(model,'annotation') -0141 if isfield(model.annotation,'note') -0142 modelSBML.notes=['<notes><body xmlns="http://www.w3.org/1999/xhtml"><p>',regexprep(model.annotation.note,'<p>|</p>',''),'</p></body></notes>']; -0143 end -0144 else -0145 modelSBML.notes='<notes><body xmlns="http://www.w3.org/1999/xhtml"><p>This file was generated using the exportModel function in RAVEN Toolbox 2 and OutputSBML in libSBML </p></body></notes>'; -0146 end +0013 % sortIds logical whether metabolites, reactions and genes +0014 % should be sorted alphabetically by their +0015 % identifiers (opt, default false) +0016 % +0017 % Usage: exportModel(model,fileName,exportGeneComplexes,supressWarnings,sortIds) +0018 if nargin<3 +0019 exportGeneComplexes=false; +0020 end +0021 if nargin<4 +0022 supressWarnings=false; +0023 end +0024 if nargin<5 +0025 sortIds=false; +0026 end +0027 if sortIds==true +0028 model=sortIdentifiers(model); +0029 end +0030 +0031 %If no subSystems are defined, then no need to use groups package +0032 if isfield(model,'subSystems') +0033 modelHasSubsystems=true; +0034 else +0035 modelHasSubsystems=false; +0036 end +0037 +0038 %The default SBML format settings, which are used as input for appropriate +0039 %libSBML functions to generate the blank SBML model structure before using +0040 %exporting in with OutputSBML to xml file +0041 sbmlLevel=3; +0042 sbmlVersion=1; +0043 sbmlPackages={'fbc'}; +0044 sbmlPackageVersions=2; +0045 if modelHasSubsystems +0046 sbmlPackages={sbmlPackages,'groups'}; +0047 sbmlPackageVersions=[sbmlPackageVersions,1]; +0048 end +0049 +0050 %Check if the "unconstrained" field is still present. This shows if +0051 %exchange metabolites have been removed +0052 if ~isfield(model,'unconstrained') +0053 if supressWarnings==false +0054 EM='There is no unconstrained field in the model structure. This means that no metabolites are considered exchange metabolites'; +0055 dispEM(EM,false); +0056 end +0057 model.unconstrained=zeros(numel(model.mets),1); +0058 end +0059 +0060 %If model id and name do not exist, make sure that default +0061 %strings are included +0062 if ~isfield(model,'id') +0063 fprintf('WARNING: The model is missing the "id" field. Uses "blankID". \n'); +0064 model.id='blankID'; +0065 end +0066 if ~isfield(model,'name') +0067 fprintf('WARNING: The model is missing the "name" field. Uses "blankName". \n'); +0068 model.name='blankName'; +0069 end +0070 +0071 %Check the model structure +0072 if supressWarnings==false +0073 checkModelStruct(model,false); +0074 end +0075 +0076 %Add several blank fields, if they do not exist already. This is to reduce +0077 %the number of conditions below +0078 if ~isfield(model,'compMiriams') +0079 model.compMiriams=cell(numel(model.comps),1); +0080 end +0081 if ~isfield(model,'inchis') +0082 model.inchis=cell(numel(model.mets),1); +0083 end +0084 if ~isfield(model,'metFormulas') +0085 model.metFormulas=cell(numel(model.mets),1); +0086 end +0087 if ~isfield(model,'metMiriams') +0088 model.metMiriams=cell(numel(model.mets),1); +0089 end +0090 if ~isfield(model,'geneMiriams') && isfield(model,'genes') +0091 model.geneMiriams=cell(numel(model.genes),1); +0092 end +0093 if ~isfield(model,'geneShortNames') && isfield(model,'genes') +0094 model.geneShortNames=cell(numel(model.genes),1); +0095 end +0096 if ~isfield(model,'subSystems') +0097 model.subSystems=cell(numel(model.rxns),1); +0098 end +0099 if ~isfield(model,'eccodes') +0100 model.eccodes=cell(numel(model.rxns),1); +0101 end +0102 if ~isfield(model,'rxnReferences') +0103 model.rxnReferences=cell(numel(model.rxns),1); +0104 end +0105 if ~isfield(model,'rxnConfidenceScores') +0106 model.rxnConfidenceScores=NaN(numel(model.rxns),1); +0107 end +0108 if ~isfield(model,'rxnNotes') +0109 model.rxnNotes=cell(numel(model.rxns),1); +0110 end +0111 if ~isfield(model,'rxnMiriams') +0112 model.rxnMiriams=cell(numel(model.rxns),1); +0113 end +0114 +0115 if sbmlLevel<3 +0116 %Check if genes have associated compartments +0117 if ~isfield(model,'geneComps') && isfield(model,'genes') +0118 if supressWarnings==false +0119 EM='There are no compartments specified for genes. All genes will be assigned to the first compartment. This is because the SBML structure requires all elements to be assigned to a compartment'; +0120 dispEM(EM,false); +0121 end +0122 model.geneComps=ones(numel(model.genes),1); +0123 end +0124 end +0125 +0126 %Convert ids to SBML-convenient format. This is to avoid the data loss when +0127 %unsupported characters are included in ids. Here we are using part from +0128 %convertSBMLID, originating from the COBRA Toolbox +0129 model.rxns=regexprep(model.rxns,'([^0-9_a-zA-Z])','__${num2str($1+0)}__'); +0130 model.mets=regexprep(model.mets,'([^0-9_a-zA-Z])','__${num2str($1+0)}__'); +0131 model.comps=regexprep(model.comps,'([^0-9_a-zA-Z])','__${num2str($1+0)}__'); +0132 if isfield(model,'genes') +0133 problemGenes=find(~cellfun('isempty',regexp(model.genes,'([^0-9_a-zA-Z])'))); +0134 originalGenes=model.genes(problemGenes); +0135 replacedGenes=regexprep(model.genes(problemGenes),'([^0-9_a-zA-Z])','__${num2str($1+0)}__'); +0136 model.genes(problemGenes)=replacedGenes; +0137 for i=1:numel(problemGenes) +0138 model.grRules = regexprep(model.grRules, ['(^|\s|\()' originalGenes{i} '($|\s|\))'], ['$1' replacedGenes{i} '$2']); +0139 end +0140 end +0141 +0142 %Generate an empty SBML structure +0143 modelSBML=getSBMLStructure(sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0144 modelSBML.metaid=model.id; +0145 modelSBML.id=model.id; +0146 modelSBML.name=model.name; 0147 -0148 modelSBML.annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_' model.id '">']; -0149 if isfield(model,'annotation') -0150 nameString=''; -0151 if isfield(model.annotation,'familyName') -0152 if ~isempty(model.annotation.familyName) -0153 nameString=['<vCard:Family>' model.annotation.familyName '</vCard:Family>']; -0154 end -0155 end -0156 if isfield(model.annotation,'givenName') -0157 if ~isempty(model.annotation.givenName) -0158 nameString=[nameString '<vCard:Given>' model.annotation.givenName '</vCard:Given>']; -0159 end -0160 end -0161 email=''; -0162 if isfield(model.annotation,'email') -0163 if ~isempty(model.annotation.email) -0164 email=['<vCard:EMAIL>' model.annotation.email '</vCard:EMAIL>']; -0165 end -0166 end -0167 org=''; -0168 if isfield(model.annotation,'organization') -0169 if ~isempty(model.annotation.organization) -0170 org=['<vCard:ORG rdf:parseType="Resource"><vCard:Orgname>' model.annotation.organization '</vCard:Orgname></vCard:ORG>']; -0171 end -0172 end -0173 if ~isempty(nameString) || ~isempty(email) || ~isempty(org) -0174 modelSBML.annotation=[modelSBML.annotation '<dc:creator><rdf:Bag><rdf:li rdf:parseType="Resource">']; -0175 if ~isempty(nameString) -0176 modelSBML.annotation=[modelSBML.annotation '<vCard:N rdf:parseType="Resource">' nameString '</vCard:N>']; -0177 end -0178 modelSBML.annotation=[modelSBML.annotation email org '</rdf:li></rdf:Bag></dc:creator>']; -0179 end -0180 end -0181 modelSBML.annotation=[modelSBML.annotation '<dcterms:created rdf:parseType="Resource">'... -0182 '<dcterms:W3CDTF>' datestr(now,'yyyy-mm-ddTHH:MM:SSZ') '</dcterms:W3CDTF>'... -0183 '</dcterms:created>'... -0184 '<dcterms:modified rdf:parseType="Resource">'... -0185 '<dcterms:W3CDTF>' datestr(now,'yyyy-mm-ddTHH:MM:SSZ') '</dcterms:W3CDTF>'... -0186 '</dcterms:modified>']; -0187 -0188 if isfield(model,'annotation') -0189 if isfield(model.annotation,'taxonomy') -0190 modelSBML.annotation=[modelSBML.annotation '<bqbiol:is><rdf:Bag><rdf:li rdf:resource="https://identifiers.org/taxonomy/' regexprep(model.annotation.taxonomy,'taxonomy/','') '"/></rdf:Bag></bqbiol:is>']; -0191 end -0192 end -0193 modelSBML.annotation=[modelSBML.annotation '</rdf:Description></rdf:RDF></annotation>']; -0194 -0195 %Prepare compartments -0196 for i=1:numel(model.comps) -0197 %Add the default values, as these will be the same in all entries -0198 if i==1 -0199 if isfield(modelSBML.compartment, 'sboTerm') -0200 modelSBML.compartment(i).sboTerm=290; -0201 end -0202 if isfield(modelSBML.compartment, 'spatialDimensions') -0203 modelSBML.compartment(i).spatialDimensions=3; -0204 end -0205 if isfield(modelSBML.compartment, 'size') -0206 modelSBML.compartment(i).size=1; -0207 end -0208 if isfield(modelSBML.compartment, 'constant') -0209 modelSBML.compartment(i).constant=1; -0210 end -0211 if isfield(modelSBML.compartment, 'isSetSize') -0212 modelSBML.compartment(i).isSetSize=1; -0213 end -0214 if isfield(modelSBML.compartment, 'isSetSpatialDimensions') -0215 modelSBML.compartment(i).isSetSpatialDimensions=1; -0216 end -0217 end -0218 %Copy the default values to the next entry as long as it is not the -0219 %last one -0220 if i<numel(model.comps) -0221 modelSBML.compartment(i+1)=modelSBML.compartment(i); -0222 end -0223 -0224 if isfield(modelSBML.compartment,'metaid') -0225 if regexp(model.comps{i},'^[^a-zA-Z_]') -0226 EM='The compartment IDs are in numeric format. For the compliance with SBML specifications, compartment IDs will be preceded with "c_" string'; -0227 dispEM(EM,false); -0228 model.comps(i)=strcat('c_',model.comps(i)); -0229 end -0230 modelSBML.compartment(i).metaid=model.comps{i}; -0231 end -0232 %Prepare Miriam strings -0233 if ~isempty(model.compMiriams{i}) -0234 [~,sbo_ind] = ismember('sbo',model.compMiriams{i}.name); -0235 if sbo_ind > 0 -0236 modelSBML.compartment(i).sboTerm=str2double(regexprep(model.compMiriams{i}.value{sbo_ind},'SBO:','','ignorecase')); -0237 % remove the SBO term from compMiriams so the information is -0238 % not duplicated in the "annotation" field later on -0239 model.compMiriams{i}.name(sbo_ind) = []; -0240 model.compMiriams{i}.value(sbo_ind) = []; -0241 end -0242 end -0243 if ~isempty(model.compMiriams{i}) && isfield(modelSBML.compartment(i),'annotation') -0244 modelSBML.compartment(i).annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_' model.comps{i} '">']; -0245 modelSBML.compartment(i).annotation=[modelSBML.compartment(i).annotation '<bqbiol:is><rdf:Bag>']; -0246 modelSBML.compartment(i).annotation=[modelSBML.compartment(i).annotation getMiriam(model.compMiriams{i}) '</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>']; -0247 end -0248 if isfield(modelSBML.compartment, 'name') -0249 modelSBML.compartment(i).name=model.compNames{i}; +0148 if isfield(model,'annotation') +0149 if isfield(model.annotation,'note') +0150 modelSBML.notes=['<notes><body xmlns="http://www.w3.org/1999/xhtml"><p>',regexprep(model.annotation.note,'<p>|</p>',''),'</p></body></notes>']; +0151 end +0152 else +0153 modelSBML.notes='<notes><body xmlns="http://www.w3.org/1999/xhtml"><p>This file was generated using the exportModel function in RAVEN Toolbox 2 and OutputSBML in libSBML </p></body></notes>'; +0154 end +0155 +0156 modelSBML.annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_' model.id '">']; +0157 if isfield(model,'annotation') +0158 nameString=''; +0159 if isfield(model.annotation,'familyName') +0160 if ~isempty(model.annotation.familyName) +0161 nameString=['<vCard:Family>' model.annotation.familyName '</vCard:Family>']; +0162 end +0163 end +0164 if isfield(model.annotation,'givenName') +0165 if ~isempty(model.annotation.givenName) +0166 nameString=[nameString '<vCard:Given>' model.annotation.givenName '</vCard:Given>']; +0167 end +0168 end +0169 email=''; +0170 if isfield(model.annotation,'email') +0171 if ~isempty(model.annotation.email) +0172 email=['<vCard:EMAIL>' model.annotation.email '</vCard:EMAIL>']; +0173 end +0174 end +0175 org=''; +0176 if isfield(model.annotation,'organization') +0177 if ~isempty(model.annotation.organization) +0178 org=['<vCard:ORG rdf:parseType="Resource"><vCard:Orgname>' model.annotation.organization '</vCard:Orgname></vCard:ORG>']; +0179 end +0180 end +0181 if ~isempty(nameString) || ~isempty(email) || ~isempty(org) +0182 modelSBML.annotation=[modelSBML.annotation '<dc:creator><rdf:Bag><rdf:li rdf:parseType="Resource">']; +0183 if ~isempty(nameString) +0184 modelSBML.annotation=[modelSBML.annotation '<vCard:N rdf:parseType="Resource">' nameString '</vCard:N>']; +0185 end +0186 modelSBML.annotation=[modelSBML.annotation email org '</rdf:li></rdf:Bag></dc:creator>']; +0187 end +0188 end +0189 modelSBML.annotation=[modelSBML.annotation '<dcterms:created rdf:parseType="Resource">'... +0190 '<dcterms:W3CDTF>' datestr(now,'yyyy-mm-ddTHH:MM:SSZ') '</dcterms:W3CDTF>'... +0191 '</dcterms:created>'... +0192 '<dcterms:modified rdf:parseType="Resource">'... +0193 '<dcterms:W3CDTF>' datestr(now,'yyyy-mm-ddTHH:MM:SSZ') '</dcterms:W3CDTF>'... +0194 '</dcterms:modified>']; +0195 +0196 if isfield(model,'annotation') +0197 if isfield(model.annotation,'taxonomy') +0198 modelSBML.annotation=[modelSBML.annotation '<bqbiol:is><rdf:Bag><rdf:li rdf:resource="https://identifiers.org/taxonomy/' regexprep(model.annotation.taxonomy,'taxonomy/','') '"/></rdf:Bag></bqbiol:is>']; +0199 end +0200 end +0201 modelSBML.annotation=[modelSBML.annotation '</rdf:Description></rdf:RDF></annotation>']; +0202 +0203 %Prepare compartments +0204 for i=1:numel(model.comps) +0205 %Add the default values, as these will be the same in all entries +0206 if i==1 +0207 if isfield(modelSBML.compartment, 'sboTerm') +0208 modelSBML.compartment(i).sboTerm=290; +0209 end +0210 if isfield(modelSBML.compartment, 'spatialDimensions') +0211 modelSBML.compartment(i).spatialDimensions=3; +0212 end +0213 if isfield(modelSBML.compartment, 'size') +0214 modelSBML.compartment(i).size=1; +0215 end +0216 if isfield(modelSBML.compartment, 'constant') +0217 modelSBML.compartment(i).constant=1; +0218 end +0219 if isfield(modelSBML.compartment, 'isSetSize') +0220 modelSBML.compartment(i).isSetSize=1; +0221 end +0222 if isfield(modelSBML.compartment, 'isSetSpatialDimensions') +0223 modelSBML.compartment(i).isSetSpatialDimensions=1; +0224 end +0225 end +0226 %Copy the default values to the next entry as long as it is not the +0227 %last one +0228 if i<numel(model.comps) +0229 modelSBML.compartment(i+1)=modelSBML.compartment(i); +0230 end +0231 +0232 if isfield(modelSBML.compartment,'metaid') +0233 if regexp(model.comps(i),'^[^a-zA-Z_]') +0234 EM='The compartment IDs are in numeric format. For the compliance with SBML specifications, compartment IDs will be preceded with "c_" string'; +0235 dispEM(EM,false); +0236 model.comps(i)=strcat('c_',model.comps(i)); +0237 end +0238 modelSBML.compartment(i).metaid=model.comps{i}; +0239 end +0240 %Prepare Miriam strings +0241 if ~isempty(model.compMiriams{i}) +0242 [~,sbo_ind] = ismember('sbo',model.compMiriams{i}.name); +0243 if sbo_ind > 0 +0244 modelSBML.compartment(i).sboTerm=str2double(regexprep(model.compMiriams{i}.value{sbo_ind},'SBO:','','ignorecase')); +0245 % remove the SBO term from compMiriams so the information is +0246 % not duplicated in the "annotation" field later on +0247 model.compMiriams{i}.name(sbo_ind) = []; +0248 model.compMiriams{i}.value(sbo_ind) = []; +0249 end 0250 end -0251 if isfield(modelSBML.compartment, 'id') -0252 modelSBML.compartment(i).id=model.comps{i}; -0253 end -0254 -0255 end -0256 -0257 %Begin writing species -0258 for i=1:numel(model.mets) -0259 %Add the default values, as these will be the same in all entries -0260 if i==1 -0261 if isfield(modelSBML.species, 'sboTerm') -0262 modelSBML.species(i).sboTerm=247; -0263 end -0264 if isfield(modelSBML.species, 'initialAmount') -0265 modelSBML.species(i).initialAmount=1; -0266 end -0267 if isfield(modelSBML.species, 'initialConcentration') -0268 modelSBML.species(i).initialConcentration=0; -0269 end -0270 if isfield(modelSBML.species, 'isSetInitialAmount') -0271 modelSBML.species(i).isSetInitialAmount=1; -0272 end -0273 if isfield(modelSBML.species, 'isSetInitialConcentration') -0274 modelSBML.species(i).isSetInitialConcentration=1; -0275 end -0276 end -0277 %Copy the default values to the next entry as long as it is not the -0278 %last one -0279 if i<numel(model.mets) -0280 modelSBML.species(i+1)=modelSBML.species(i); -0281 end -0282 -0283 if isfield(modelSBML.species,'metaid') -0284 modelSBML.species(i).metaid=['M_' model.mets{i}]; -0285 end -0286 if isfield(modelSBML.species, 'name') -0287 modelSBML.species(i).name=model.metNames{i}; -0288 end -0289 if isfield(modelSBML.species, 'id') -0290 modelSBML.species(i).id=['M_' model.mets{i}]; -0291 end -0292 if isfield(modelSBML.species, 'compartment') -0293 modelSBML.species(i).compartment=model.comps{model.metComps(i)}; -0294 end -0295 if isfield(model,'unconstrained') -0296 if model.unconstrained(i) -0297 modelSBML.species(i).boundaryCondition=1; -0298 end +0251 if ~isempty(model.compMiriams{i}) && isfield(modelSBML.compartment(i),'annotation') +0252 modelSBML.compartment(i).annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_' model.comps{i} '">']; +0253 modelSBML.compartment(i).annotation=[modelSBML.compartment(i).annotation '<bqbiol:is><rdf:Bag>']; +0254 modelSBML.compartment(i).annotation=[modelSBML.compartment(i).annotation getMiriam(model.compMiriams{i}) '</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>']; +0255 end +0256 if isfield(modelSBML.compartment, 'name') +0257 modelSBML.compartment(i).name=model.compNames{i}; +0258 end +0259 if isfield(modelSBML.compartment, 'id') +0260 modelSBML.compartment(i).id=model.comps{i}; +0261 end +0262 +0263 end +0264 +0265 %Begin writing species +0266 for i=1:numel(model.mets) +0267 %Add the default values, as these will be the same in all entries +0268 if i==1 +0269 if isfield(modelSBML.species, 'sboTerm') +0270 modelSBML.species(i).sboTerm=247; +0271 end +0272 if isfield(modelSBML.species, 'initialAmount') +0273 modelSBML.species(i).initialAmount=1; +0274 end +0275 if isfield(modelSBML.species, 'initialConcentration') +0276 modelSBML.species(i).initialConcentration=0; +0277 end +0278 if isfield(modelSBML.species, 'isSetInitialAmount') +0279 modelSBML.species(i).isSetInitialAmount=1; +0280 end +0281 if isfield(modelSBML.species, 'isSetInitialConcentration') +0282 modelSBML.species(i).isSetInitialConcentration=1; +0283 end +0284 end +0285 %Copy the default values to the next entry as long as it is not the +0286 %last one +0287 if i<numel(model.mets) +0288 modelSBML.species(i+1)=modelSBML.species(i); +0289 end +0290 +0291 if isfield(modelSBML.species,'metaid') +0292 modelSBML.species(i).metaid=['M_' model.mets{i}]; +0293 end +0294 if isfield(modelSBML.species, 'name') +0295 modelSBML.species(i).name=model.metNames{i}; +0296 end +0297 if isfield(modelSBML.species, 'id') +0298 modelSBML.species(i).id=['M_' model.mets{i}]; 0299 end -0300 if isfield(modelSBML.species, 'fbc_charge') && isfield(model,'metCharges') -0301 if ~isnan(model.metCharges(i)) -0302 modelSBML.species(i).fbc_charge=model.metCharges(i); -0303 modelSBML.species(i).isSetfbc_charge=1; -0304 else -0305 modelSBML.species(i).isSetfbc_charge=0; +0300 if isfield(modelSBML.species, 'compartment') +0301 modelSBML.species(i).compartment=model.comps{model.metComps(i)}; +0302 end +0303 if isfield(model,'unconstrained') +0304 if model.unconstrained(i) +0305 modelSBML.species(i).boundaryCondition=1; 0306 end 0307 end -0308 if ~isempty(model.metMiriams{i}) -0309 [~,sbo_ind] = ismember('sbo',model.metMiriams{i}.name); -0310 if sbo_ind > 0 -0311 modelSBML.species(i).sboTerm=str2double(regexprep(model.metMiriams{i}.value{sbo_ind},'SBO:','','ignorecase')); -0312 % remove the SBO term from metMiriams so the information is -0313 % not duplicated in the "annotation" field later on -0314 model.metMiriams{i}.name(sbo_ind) = []; -0315 model.metMiriams{i}.value(sbo_ind) = []; -0316 end -0317 end -0318 if isfield(modelSBML.species,'annotation') -0319 if ~isempty(model.metMiriams{i}) || ~isempty(model.metFormulas{i}) -0320 hasInchi=false; -0321 if ~isempty(model.metFormulas{i}) -0322 %Only export formula if there is no InChI. This is because -0323 %the metFormulas field is populated by InChIs if available -0324 if ~isempty(model.inchis{i}) -0325 hasInchi=true; -0326 end -0327 if hasInchi==false -0328 modelSBML.species(i).fbc_chemicalFormula=model.metFormulas{i}; -0329 end -0330 end -0331 if ~isempty(model.metMiriams{i}) || hasInchi==true -0332 modelSBML.species(i).annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_M_' model.mets{i} '">']; -0333 modelSBML.species(i).annotation=[modelSBML.species(i).annotation '<bqbiol:is><rdf:Bag>']; -0334 if ~isempty(model.metMiriams{i}) -0335 modelSBML.species(i).annotation=[modelSBML.species(i).annotation getMiriam(model.metMiriams{i})]; -0336 end -0337 if hasInchi==true -0338 modelSBML.species(i).annotation=[modelSBML.species(i).annotation '<rdf:li rdf:resource="https://identifiers.org/inchi/InChI=' regexprep(model.inchis{i},'^InChI=','') '"/>']; -0339 modelSBML.species(i).fbc_chemicalFormula=char(regexp(model.inchis{i}, '/(\w+)/', 'tokens', 'once')); -0340 end -0341 modelSBML.species(i).annotation=[modelSBML.species(i).annotation '</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>']; -0342 end -0343 end -0344 end -0345 end -0346 -0347 if isfield(model,'genes') -0348 for i=1:numel(model.genes) -0349 %Add the default values, as these will be the same in all entries -0350 if i==1 -0351 if isfield(modelSBML.fbc_geneProduct, 'sboTerm') -0352 modelSBML.fbc_geneProduct(i).sboTerm=243; -0353 end -0354 end -0355 %Copy the default values to the next index as long as it is not the -0356 %last one -0357 if i<numel(model.genes) -0358 modelSBML.fbc_geneProduct(i+1)=modelSBML.fbc_geneProduct(i); -0359 end -0360 -0361 if isfield(modelSBML.fbc_geneProduct,'metaid') -0362 modelSBML.fbc_geneProduct(i).metaid=model.genes{i}; -0363 end -0364 if ~isempty(model.geneMiriams{i}) -0365 [~,sbo_ind] = ismember('sbo',model.geneMiriams{i}.name); -0366 if sbo_ind > 0 -0367 modelSBML.fbc_geneProduct(i).sboTerm=str2double(regexprep(model.geneMiriams{i}.value{sbo_ind},'SBO:','','ignorecase')); -0368 % remove the SBO term from compMiriams so the information is -0369 % not duplicated in the "annotation" field later on -0370 model.geneMiriams{i}.name(sbo_ind) = []; -0371 model.geneMiriams{i}.value(sbo_ind) = []; -0372 end -0373 end -0374 if ~isempty(model.geneMiriams{i}) && isfield(modelSBML.fbc_geneProduct(i),'annotation') -0375 modelSBML.fbc_geneProduct(i).annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_' model.genes{i} '">']; -0376 modelSBML.fbc_geneProduct(i).annotation=[modelSBML.fbc_geneProduct(i).annotation '<bqbiol:is><rdf:Bag>']; -0377 modelSBML.fbc_geneProduct(i).annotation=[modelSBML.fbc_geneProduct(i).annotation getMiriam(model.geneMiriams{i}) '</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>']; -0378 end -0379 if isfield(modelSBML.fbc_geneProduct, 'fbc_id') -0380 modelSBML.fbc_geneProduct(i).fbc_id=model.genes{i}; +0308 if isfield(modelSBML.species, 'fbc_charge') && isfield(model,'metCharges') +0309 if ~isnan(model.metCharges(i)) +0310 modelSBML.species(i).fbc_charge=model.metCharges(i); +0311 modelSBML.species(i).isSetfbc_charge=1; +0312 else +0313 modelSBML.species(i).isSetfbc_charge=0; +0314 end +0315 end +0316 if ~isempty(model.metMiriams{i}) +0317 [~,sbo_ind] = ismember('sbo',model.metMiriams{i}.name); +0318 if sbo_ind > 0 +0319 modelSBML.species(i).sboTerm=str2double(regexprep(model.metMiriams{i}.value{sbo_ind},'SBO:','','ignorecase')); +0320 % remove the SBO term from metMiriams so the information is +0321 % not duplicated in the "annotation" field later on +0322 model.metMiriams{i}.name(sbo_ind) = []; +0323 model.metMiriams{i}.value(sbo_ind) = []; +0324 end +0325 end +0326 if isfield(modelSBML.species,'annotation') +0327 if ~isempty(model.metMiriams{i}) || ~isempty(model.metFormulas{i}) +0328 hasInchi=false; +0329 if ~isempty(model.metFormulas{i}) +0330 %Only export formula if there is no InChI. This is because +0331 %the metFormulas field is populated by InChIs if available +0332 if ~isempty(model.inchis{i}) +0333 hasInchi=true; +0334 end +0335 if hasInchi==false +0336 modelSBML.species(i).fbc_chemicalFormula=model.metFormulas{i}; +0337 end +0338 end +0339 if ~isempty(model.metMiriams{i}) || hasInchi==true +0340 modelSBML.species(i).annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_M_' model.mets{i} '">']; +0341 modelSBML.species(i).annotation=[modelSBML.species(i).annotation '<bqbiol:is><rdf:Bag>']; +0342 if ~isempty(model.metMiriams{i}) +0343 modelSBML.species(i).annotation=[modelSBML.species(i).annotation getMiriam(model.metMiriams{i})]; +0344 end +0345 if hasInchi==true +0346 modelSBML.species(i).annotation=[modelSBML.species(i).annotation '<rdf:li rdf:resource="https://identifiers.org/inchi/InChI=' regexprep(model.inchis{i},'^InChI=','') '"/>']; +0347 modelSBML.species(i).fbc_chemicalFormula=char(regexp(model.inchis{i}, '/(\w+)/', 'tokens', 'once')); +0348 end +0349 modelSBML.species(i).annotation=[modelSBML.species(i).annotation '</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>']; +0350 end +0351 end +0352 end +0353 end +0354 +0355 if isfield(model,'genes') +0356 for i=1:numel(model.genes) +0357 %Add the default values, as these will be the same in all entries +0358 if i==1 +0359 if isfield(modelSBML.fbc_geneProduct, 'sboTerm') +0360 modelSBML.fbc_geneProduct(i).sboTerm=243; +0361 end +0362 end +0363 %Copy the default values to the next index as long as it is not the +0364 %last one +0365 if i<numel(model.genes) +0366 modelSBML.fbc_geneProduct(i+1)=modelSBML.fbc_geneProduct(i); +0367 end +0368 +0369 if isfield(modelSBML.fbc_geneProduct,'metaid') +0370 modelSBML.fbc_geneProduct(i).metaid=model.genes{i}; +0371 end +0372 if ~isempty(model.geneMiriams{i}) +0373 [~,sbo_ind] = ismember('sbo',model.geneMiriams{i}.name); +0374 if sbo_ind > 0 +0375 modelSBML.fbc_geneProduct(i).sboTerm=str2double(regexprep(model.geneMiriams{i}.value{sbo_ind},'SBO:','','ignorecase')); +0376 % remove the SBO term from compMiriams so the information is +0377 % not duplicated in the "annotation" field later on +0378 model.geneMiriams{i}.name(sbo_ind) = []; +0379 model.geneMiriams{i}.value(sbo_ind) = []; +0380 end 0381 end -0382 if isfield(modelSBML.fbc_geneProduct, 'fbc_label') && isfield(model,'geneShortNames') -0383 if isempty(model.geneShortNames{i}) -0384 modelSBML.fbc_geneProduct(i).fbc_label=model.genes{i}; -0385 else -0386 modelSBML.fbc_geneProduct(i).fbc_label=model.geneShortNames{i}; -0387 end -0388 end -0389 end -0390 if exportGeneComplexes==true -0391 %Also add the complexes as genes. This is done by splitting grRules -0392 %on "or" and adding the ones which contain several genes -0393 geneComplexes={}; -0394 if isfield(model,'grRules') -0395 %Only grRules which contain " and " can be complexes -0396 uniqueRules=unique(model.grRules); -0397 I=cellfun(@any,strfind(uniqueRules,' and ')); -0398 uniqueRules(~I)=[]; -0399 uniqueRules=strrep(uniqueRules,'(',''); -0400 uniqueRules=strrep(uniqueRules,')',''); -0401 uniqueRules=strrep(uniqueRules,' and ',':'); -0402 for i=1:numel(uniqueRules) -0403 genes=regexp(uniqueRules(i),' or ','split'); -0404 genes=genes{1}(:); -0405 %Check which ones are complexes -0406 I=cellfun(@any,strfind(genes,':')); -0407 geneComplexes=[geneComplexes;genes(I)]; -0408 end -0409 end -0410 geneComplexes=unique(geneComplexes); -0411 if ~isempty(geneComplexes) -0412 %Then add them as genes. There is a possiblity that a complex -0413 %A&B is added as separate from B&A. This is not really an issue -0414 %so this is not dealt with -0415 for i=1:numel(geneComplexes) -0416 modelSBML.fbc_geneProduct(numel(model.genes)+i)=modelSBML.fbc_geneProduct(1); -0417 if isfield(modelSBML.fbc_geneProduct,'metaid') -0418 modelSBML.fbc_geneProduct(numel(model.genes)+i).metaid=geneComplexes{i}; -0419 end -0420 if isfield(modelSBML.fbc_geneProduct,'fbc_id') -0421 modelSBML.fbc_geneProduct(numel(model.genes)+i).fbc_id=geneComplexes{i}; -0422 else -0423 modelSBML.fbc_geneProduct(i).fbc_label=modelSBML.fbc_geneProduct(i).fbc_id; -0424 end -0425 end -0426 end -0427 end -0428 end -0429 -0430 %Generate a list of unique fbc_bound names -0431 totalValues=[model.lb; model.ub]; -0432 totalNames=cell(size(totalValues,1),1); -0433 -0434 listUniqueValues=unique(totalValues); -0435 -0436 for i=1:length(listUniqueValues) -0437 listUniqueNames{i,1}=['FB',num2str(i),'N',num2str(abs(round(listUniqueValues(i))))]; % create unique flux bound IDs. -0438 ind=find(ismember(totalValues,listUniqueValues(i))); -0439 totalNames(ind)=listUniqueNames(i,1); -0440 end +0382 if ~isempty(model.geneMiriams{i}) && isfield(modelSBML.fbc_geneProduct(i),'annotation') +0383 modelSBML.fbc_geneProduct(i).annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_' model.genes{i} '">']; +0384 modelSBML.fbc_geneProduct(i).annotation=[modelSBML.fbc_geneProduct(i).annotation '<bqbiol:is><rdf:Bag>']; +0385 modelSBML.fbc_geneProduct(i).annotation=[modelSBML.fbc_geneProduct(i).annotation getMiriam(model.geneMiriams{i}) '</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>']; +0386 end +0387 if isfield(modelSBML.fbc_geneProduct, 'fbc_id') +0388 modelSBML.fbc_geneProduct(i).fbc_id=model.genes{i}; +0389 end +0390 if isfield(modelSBML.fbc_geneProduct, 'fbc_label') && isfield(model,'geneShortNames') +0391 if isempty(model.geneShortNames{i}) +0392 modelSBML.fbc_geneProduct(i).fbc_label=model.genes{i}; +0393 else +0394 modelSBML.fbc_geneProduct(i).fbc_label=model.geneShortNames{i}; +0395 end +0396 end +0397 end +0398 if exportGeneComplexes==true +0399 %Also add the complexes as genes. This is done by splitting grRules +0400 %on "or" and adding the ones which contain several genes +0401 geneComplexes={}; +0402 if isfield(model,'grRules') +0403 %Only grRules which contain " and " can be complexes +0404 uniqueRules=unique(model.grRules); +0405 I=cellfun(@any,strfind(uniqueRules,' and ')); +0406 uniqueRules(~I)=[]; +0407 uniqueRules=strrep(uniqueRules,'(',''); +0408 uniqueRules=strrep(uniqueRules,')',''); +0409 uniqueRules=strrep(uniqueRules,' and ',':'); +0410 for i=1:numel(uniqueRules) +0411 genes=regexp(uniqueRules(i),' or ','split'); +0412 genes=genes{1}(:); +0413 %Check which ones are complexes +0414 I=cellfun(@any,strfind(genes,':')); +0415 geneComplexes=[geneComplexes;genes(I)]; +0416 end +0417 end +0418 geneComplexes=unique(geneComplexes); +0419 if ~isempty(geneComplexes) +0420 %Then add them as genes. There is a possiblity that a complex +0421 %A&B is added as separate from B&A. This is not really an issue +0422 %so this is not dealt with +0423 for i=1:numel(geneComplexes) +0424 modelSBML.fbc_geneProduct(numel(model.genes)+i)=modelSBML.fbc_geneProduct(1); +0425 if isfield(modelSBML.fbc_geneProduct,'metaid') +0426 modelSBML.fbc_geneProduct(numel(model.genes)+i).metaid=geneComplexes{i}; +0427 end +0428 if isfield(modelSBML.fbc_geneProduct,'fbc_id') +0429 modelSBML.fbc_geneProduct(numel(model.genes)+i).fbc_id=geneComplexes{i}; +0430 else +0431 modelSBML.fbc_geneProduct(i).fbc_label=modelSBML.fbc_geneProduct(i).fbc_id; +0432 end +0433 end +0434 end +0435 end +0436 end +0437 +0438 %Generate a list of unique fbc_bound names +0439 totalValues=[model.lb; model.ub]; +0440 totalNames=cell(size(totalValues,1),1); 0441 -0442 for i=1:length(listUniqueNames) -0443 %Add the default values, as these will be the same in all entries -0444 if i==1 -0445 if isfield(modelSBML.parameter, 'constant') -0446 modelSBML.parameter(i).constant=1; -0447 end -0448 if isfield(modelSBML.parameter, 'isSetValue') -0449 modelSBML.parameter(i).isSetValue=1; -0450 end -0451 end -0452 %Copy the default values to the next index as long as it is not the -0453 %last one -0454 if i<numel(listUniqueNames) -0455 modelSBML.parameter(i+1)=modelSBML.parameter(i); -0456 end -0457 modelSBML.parameter(i).id=listUniqueNames{i}; -0458 modelSBML.parameter(i).value=listUniqueValues(i); -0459 end -0460 -0461 for i=1:numel(model.rxns) -0462 %Add the default values, as these will be the same in all entries -0463 if i==1 -0464 if isfield(modelSBML.reaction, 'sboTerm') -0465 modelSBML.reaction(i).sboTerm=176; -0466 end -0467 if isfield(modelSBML.reaction, 'isSetFast') -0468 modelSBML.reaction(i).isSetFast=1; -0469 end -0470 end -0471 %Copy the default values to the next index as long as it is not the -0472 %last one -0473 if i<numel(model.rxns) -0474 modelSBML.reaction(i+1)=modelSBML.reaction(i); -0475 end -0476 -0477 if isfield(modelSBML.reaction,'metaid') -0478 modelSBML.reaction(i).metaid=['R_' model.rxns{i}]; -0479 end -0480 -0481 %Export notes information -0482 if (~isnan(model.rxnConfidenceScores(i)) || ~isempty(model.rxnReferences{i}) || ~isempty(model.rxnNotes{i})) -0483 modelSBML.reaction(i).notes='<notes><body xmlns="http://www.w3.org/1999/xhtml">'; -0484 if ~isnan(model.rxnConfidenceScores(i)) -0485 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes '<p>Confidence Level: ' num2str(model.rxnConfidenceScores(i)) '</p>']; -0486 end -0487 if ~isempty(model.rxnReferences{i}) -0488 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes '<p>AUTHORS: ' model.rxnReferences{i} '</p>']; -0489 end -0490 if ~isempty(model.rxnNotes{i}) -0491 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes '<p>NOTES: ' model.rxnNotes{i} '</p>']; -0492 end -0493 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes '</body></notes>']; -0494 end -0495 -0496 % Export SBO terms from rxnMiriams -0497 if ~isempty(model.rxnMiriams{i}) -0498 [~,sbo_ind] = ismember('sbo',model.rxnMiriams{i}.name); -0499 if sbo_ind > 0 -0500 modelSBML.reaction(i).sboTerm=str2double(regexprep(model.rxnMiriams{i}.value{sbo_ind},'SBO:','','ignorecase')); -0501 % remove the SBO term from rxnMiriams so the information is not -0502 % duplicated in the "annotation" field later on -0503 model.rxnMiriams{i}.name(sbo_ind) = []; -0504 model.rxnMiriams{i}.value(sbo_ind) = []; -0505 end -0506 end -0507 -0508 %Export annotation information from rxnMiriams -0509 if (~isempty(model.rxnMiriams{i}) && isfield(modelSBML.reaction(i),'annotation')) || ~isempty(model.eccodes{i}) -0510 modelSBML.reaction(i).annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_R_' model.rxns{i} '">']; -0511 modelSBML.reaction(i).annotation=[modelSBML.reaction(i).annotation '<bqbiol:is><rdf:Bag>']; -0512 if ~isempty(model.eccodes{i}) -0513 eccodes=regexp(model.eccodes{i},';','split'); -0514 for j=1:numel(eccodes) -0515 modelSBML.reaction(i).annotation=[modelSBML.reaction(i).annotation '<rdf:li rdf:resource="https://identifiers.org/ec-code/' regexprep(eccodes{j},'ec-code/|EC','') '"/>']; -0516 end -0517 end -0518 modelSBML.reaction(i).annotation=[modelSBML.reaction(i).annotation getMiriam(model.rxnMiriams{i}) '</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>']; -0519 end -0520 -0521 if isfield(modelSBML.reaction, 'name') -0522 modelSBML.reaction(i).name=model.rxnNames{i}; -0523 end -0524 if isfield(modelSBML.reaction, 'id') -0525 modelSBML.reaction(i).id=['R_' model.rxns{i}]; -0526 end -0527 -0528 %Add the information about reactants and products -0529 involvedMets=addReactantsProducts(model,modelSBML,i); -0530 for j=1:numel(involvedMets.reactant) -0531 if j<numel(involvedMets.reactant) -0532 modelSBML.reaction(i).reactant(j+1)=modelSBML.reaction(i).reactant(j); -0533 end -0534 modelSBML.reaction(i).reactant(j).species=involvedMets.reactant(j).species; -0535 modelSBML.reaction(i).reactant(j).stoichiometry=involvedMets.reactant(j).stoichiometry; -0536 modelSBML.reaction(i).reactant(j).isSetStoichiometry=involvedMets.reactant(j).isSetStoichiometry; -0537 modelSBML.reaction(i).reactant(j).constant=involvedMets.reactant(j).constant; -0538 end -0539 if numel(involvedMets.reactant)==0 -0540 modelSBML.reaction(i).reactant=''; -0541 end -0542 for j=1:numel(involvedMets.product) -0543 if j<numel(involvedMets.product) -0544 modelSBML.reaction(i).product(j+1)=modelSBML.reaction(i).product(j); -0545 end -0546 modelSBML.reaction(i).product(j).species=involvedMets.product(j).species; -0547 modelSBML.reaction(i).product(j).stoichiometry=involvedMets.product(j).stoichiometry; -0548 modelSBML.reaction(i).product(j).isSetStoichiometry=involvedMets.product(j).isSetStoichiometry; -0549 modelSBML.reaction(i).product(j).constant=involvedMets.product(j).constant; -0550 end -0551 if numel(involvedMets.product)==0 -0552 modelSBML.reaction(i).product=''; -0553 end -0554 %Export reversibility information. Reactions are irreversible by -0555 %default -0556 if model.rev(i)==1 -0557 modelSBML.reaction(i).reversible=1; +0442 listUniqueValues=unique(totalValues); +0443 +0444 for i=1:length(listUniqueValues) +0445 listUniqueNames{i,1}=['FB',num2str(i),'N',num2str(abs(round(listUniqueValues(i))))]; % create unique flux bound IDs. +0446 ind=find(ismember(totalValues,listUniqueValues(i))); +0447 totalNames(ind)=listUniqueNames(i,1); +0448 end +0449 +0450 for i=1:length(listUniqueNames) +0451 %Add the default values, as these will be the same in all entries +0452 if i==1 +0453 if isfield(modelSBML.parameter, 'constant') +0454 modelSBML.parameter(i).constant=1; +0455 end +0456 if isfield(modelSBML.parameter, 'isSetValue') +0457 modelSBML.parameter(i).isSetValue=1; +0458 end +0459 end +0460 %Copy the default values to the next index as long as it is not the +0461 %last one +0462 if i<numel(listUniqueNames) +0463 modelSBML.parameter(i+1)=modelSBML.parameter(i); +0464 end +0465 modelSBML.parameter(i).id=listUniqueNames{i}; +0466 modelSBML.parameter(i).value=listUniqueValues(i); +0467 end +0468 +0469 for i=1:numel(model.rxns) +0470 %Add the default values, as these will be the same in all entries +0471 if i==1 +0472 if isfield(modelSBML.reaction, 'sboTerm') +0473 modelSBML.reaction(i).sboTerm=176; +0474 end +0475 if isfield(modelSBML.reaction, 'isSetFast') +0476 modelSBML.reaction(i).isSetFast=1; +0477 end +0478 end +0479 %Copy the default values to the next index as long as it is not the +0480 %last one +0481 if i<numel(model.rxns) +0482 modelSBML.reaction(i+1)=modelSBML.reaction(i); +0483 end +0484 +0485 if isfield(modelSBML.reaction,'metaid') +0486 modelSBML.reaction(i).metaid=['R_' model.rxns{i}]; +0487 end +0488 +0489 %Export notes information +0490 if (~isnan(model.rxnConfidenceScores(i)) || ~isempty(model.rxnReferences{i}) || ~isempty(model.rxnNotes{i})) +0491 modelSBML.reaction(i).notes='<notes><body xmlns="http://www.w3.org/1999/xhtml">'; +0492 if ~isnan(model.rxnConfidenceScores(i)) +0493 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes '<p>Confidence Level: ' num2str(model.rxnConfidenceScores(i)) '</p>']; +0494 end +0495 if ~isempty(model.rxnReferences{i}) +0496 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes '<p>AUTHORS: ' model.rxnReferences{i} '</p>']; +0497 end +0498 if ~isempty(model.rxnNotes{i}) +0499 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes '<p>NOTES: ' model.rxnNotes{i} '</p>']; +0500 end +0501 modelSBML.reaction(i).notes=[modelSBML.reaction(i).notes '</body></notes>']; +0502 end +0503 +0504 % Export SBO terms from rxnMiriams +0505 if ~isempty(model.rxnMiriams{i}) +0506 [~,sbo_ind] = ismember('sbo',model.rxnMiriams{i}.name); +0507 if sbo_ind > 0 +0508 modelSBML.reaction(i).sboTerm=str2double(regexprep(model.rxnMiriams{i}.value{sbo_ind},'SBO:','','ignorecase')); +0509 % remove the SBO term from rxnMiriams so the information is not +0510 % duplicated in the "annotation" field later on +0511 model.rxnMiriams{i}.name(sbo_ind) = []; +0512 model.rxnMiriams{i}.value(sbo_ind) = []; +0513 end +0514 end +0515 +0516 %Export annotation information from rxnMiriams +0517 if (~isempty(model.rxnMiriams{i}) && isfield(modelSBML.reaction(i),'annotation')) || ~isempty(model.eccodes{i}) +0518 modelSBML.reaction(i).annotation=['<annotation><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/"><rdf:Description rdf:about="#meta_R_' model.rxns{i} '">']; +0519 modelSBML.reaction(i).annotation=[modelSBML.reaction(i).annotation '<bqbiol:is><rdf:Bag>']; +0520 if ~isempty(model.eccodes{i}) +0521 eccodes=regexp(model.eccodes{i},';','split'); +0522 for j=1:numel(eccodes) +0523 modelSBML.reaction(i).annotation=[modelSBML.reaction(i).annotation '<rdf:li rdf:resource="https://identifiers.org/ec-code/' regexprep(eccodes{j},'ec-code/|EC','') '"/>']; +0524 end +0525 end +0526 modelSBML.reaction(i).annotation=[modelSBML.reaction(i).annotation getMiriam(model.rxnMiriams{i}) '</rdf:Bag></bqbiol:is></rdf:Description></rdf:RDF></annotation>']; +0527 end +0528 +0529 if isfield(modelSBML.reaction, 'name') +0530 modelSBML.reaction(i).name=model.rxnNames{i}; +0531 end +0532 if isfield(modelSBML.reaction, 'id') +0533 modelSBML.reaction(i).id=['R_' model.rxns{i}]; +0534 end +0535 +0536 %Add the information about reactants and products +0537 involvedMets=addReactantsProducts(model,modelSBML,i); +0538 for j=1:numel(involvedMets.reactant) +0539 if j<numel(involvedMets.reactant) +0540 modelSBML.reaction(i).reactant(j+1)=modelSBML.reaction(i).reactant(j); +0541 end +0542 modelSBML.reaction(i).reactant(j).species=involvedMets.reactant(j).species; +0543 modelSBML.reaction(i).reactant(j).stoichiometry=involvedMets.reactant(j).stoichiometry; +0544 modelSBML.reaction(i).reactant(j).isSetStoichiometry=involvedMets.reactant(j).isSetStoichiometry; +0545 modelSBML.reaction(i).reactant(j).constant=involvedMets.reactant(j).constant; +0546 end +0547 if numel(involvedMets.reactant)==0 +0548 modelSBML.reaction(i).reactant=''; +0549 end +0550 for j=1:numel(involvedMets.product) +0551 if j<numel(involvedMets.product) +0552 modelSBML.reaction(i).product(j+1)=modelSBML.reaction(i).product(j); +0553 end +0554 modelSBML.reaction(i).product(j).species=involvedMets.product(j).species; +0555 modelSBML.reaction(i).product(j).stoichiometry=involvedMets.product(j).stoichiometry; +0556 modelSBML.reaction(i).product(j).isSetStoichiometry=involvedMets.product(j).isSetStoichiometry; +0557 modelSBML.reaction(i).product(j).constant=involvedMets.product(j).constant; 0558 end -0559 if isfield(model, 'rxnComps') -0560 modelSBML.reaction(i).compartment=model.comps{model.rxnComps(i)}; +0559 if numel(involvedMets.product)==0 +0560 modelSBML.reaction(i).product=''; 0561 end -0562 if isfield(model, 'grRules') -0563 modelSBML.reaction(i).fbc_geneProductAssociation.fbc_association.fbc_association=model.grRules{i}; -0564 end -0565 modelSBML.reaction(i).fbc_lowerFluxBound=totalNames{i}; -0566 modelSBML.reaction(i).fbc_upperFluxBound=totalNames{length(model.lb)+i}; -0567 end -0568 -0569 %Prepare subSystems Code taken from COBRA functions getModelSubSystems, -0570 %writeSBML, findRxnsFromSubSystem under GNU General Public License v3.0, -0571 %license file in readme/GPL.MD. Code modified for RAVEN -0572 if modelHasSubsystems -0573 modelSBML.groups_group.groups_kind = 'partonomy'; -0574 modelSBML.groups_group.sboTerm = 633; -0575 tmpStruct=modelSBML.groups_group; +0562 %Export reversibility information. Reactions are irreversible by +0563 %default +0564 if model.rev(i)==1 +0565 modelSBML.reaction(i).reversible=1; +0566 end +0567 if isfield(model, 'rxnComps') +0568 modelSBML.reaction(i).compartment=model.comps{model.rxnComps(i)}; +0569 end +0570 if isfield(model, 'grRules') +0571 modelSBML.reaction(i).fbc_geneProductAssociation.fbc_association.fbc_association=model.grRules{i}; +0572 end +0573 modelSBML.reaction(i).fbc_lowerFluxBound=totalNames{i}; +0574 modelSBML.reaction(i).fbc_upperFluxBound=totalNames{length(model.lb)+i}; +0575 end 0576 -0577 rxns=strcat('R_',model.rxns); -0578 if ~any(cellfun(@iscell,model.subSystems)) -0579 if ~any(~cellfun(@isempty,model.subSystems)) -0580 subSystems = {}; -0581 else -0582 subSystems = setdiff(model.subSystems,''); -0583 end -0584 else -0585 orderedSubs = cellfun(@(x) columnVector(x),model.subSystems,'UniformOUtput',false); -0586 subSystems = setdiff(vertcat(orderedSubs{:}),''); -0587 end -0588 if isempty(subSystems) -0589 subSystems = {}; -0590 end -0591 if ~isempty(subSystems) -0592 %Build the groups for the group package -0593 groupIDs = strcat('group',cellfun(@num2str, num2cell(1:length(subSystems)),'UniformOutput',false)); -0594 for i = 1:length(subSystems) -0595 cgroup = tmpStruct; -0596 if ~any(cellfun(@iscell,model.subSystems)) -0597 present = ismember(model.subSystems,subSystems{i}); -0598 else -0599 present = cellfun(@(x) any(ismember(x,subSystems{i})),model.subSystems); -0600 end -0601 groupMembers = rxns(present); -0602 for j = 1:numel(groupMembers) -0603 cMember = tmpStruct.groups_member; -0604 cMember.groups_idRef = groupMembers{j}; -0605 if j == 1 -0606 cgroup.groups_member = cMember; -0607 else -0608 cgroup.groups_member(j) = cMember; -0609 end -0610 end -0611 cgroup.groups_id = groupIDs{i}; -0612 cgroup.groups_name = subSystems{i}; -0613 if i == 1 -0614 modelSBML.groups_group = cgroup; -0615 else -0616 modelSBML.groups_group(i) = cgroup; -0617 end -0618 end -0619 end -0620 end -0621 -0622 %Prepare fbc_objective subfield -0623 -0624 modelSBML.fbc_objective.fbc_type='maximize'; -0625 modelSBML.fbc_objective.fbc_id='obj'; -0626 -0627 ind=find(model.c); -0628 -0629 if isempty(ind) -0630 modelSBML.fbc_objective.fbc_fluxObjective.fbc_coefficient=0; -0631 EM='The objective function is not defined. The model will be exported as it is. Notice that having undefined objective function may produce warnings related to "fbc:coefficient" and "fbc:reaction" in SBML Validator'; -0632 dispEM(EM,false); -0633 else -0634 for i=1:length(ind) -0635 %Copy the default values to the next index as long as it is not the -0636 %last one -0637 if i<numel(ind) -0638 modelSBML.reaction(i+1)=modelSBML.reaction(i); -0639 end -0640 values=model.c(model.c~=0); -0641 modelSBML.fbc_objective(i).fbc_fluxObjective.fbc_reaction=modelSBML.reaction(ind(i)).id; -0642 modelSBML.fbc_objective(i).fbc_fluxObjective.fbc_coefficient=values(i); -0643 modelSBML.fbc_objective(i).fbc_fluxObjective.isSetfbc_coefficient=1; -0644 end -0645 end -0646 -0647 modelSBML.fbc_activeObjective=modelSBML.fbc_objective.fbc_id; -0648 -0649 fbcStr=['http://www.sbml.org/sbml/level', num2str(sbmlLevel), '/version', num2str(sbmlVersion), '/fbc/version',num2str(sbmlPackageVersions(1))]; -0650 if modelHasSubsystems -0651 groupStr=['http://www.sbml.org/sbml/level', num2str(sbmlLevel), '/version', num2str(sbmlVersion), '/groups/version',num2str(sbmlPackageVersions(2))]; -0652 modelSBML.namespaces=struct('prefix',{'','fbc','groups'},... -0653 'uri',{['http://www.sbml.org/sbml/level', num2str(sbmlLevel), '/version', num2str(sbmlVersion), '/core'],... -0654 fbcStr,groupStr}); -0655 else -0656 modelSBML.namespaces=struct('prefix',{'','fbc'},... -0657 'uri',{['http://www.sbml.org/sbml/level', num2str(sbmlLevel), '/version', num2str(sbmlVersion), '/core'],... -0658 fbcStr}); -0659 end -0660 -0661 if sbmlPackageVersions(1) == 2 -0662 modelSBML.fbc_strict=1; -0663 end -0664 -0665 modelSBML.rule=[]; -0666 modelSBML.constraint=[]; -0667 -0668 OutputSBML(modelSBML,fileName,1,0,[1,0]); -0669 end -0670 -0671 -0672 function modelSBML=getSBMLStructure(sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions) -0673 %Returns the blank SBML model structure by using appropriate libSBML -0674 %functions. This creates structure by considering three levels +0577 %Prepare subSystems Code taken from COBRA functions getModelSubSystems, +0578 %writeSBML, findRxnsFromSubSystem under GNU General Public License v3.0, +0579 %license file in readme/GPL.MD. Code modified for RAVEN +0580 if modelHasSubsystems +0581 modelSBML.groups_group.groups_kind = 'partonomy'; +0582 modelSBML.groups_group.sboTerm = 633; +0583 tmpStruct=modelSBML.groups_group; +0584 +0585 rxns=strcat('R_',model.rxns); +0586 if ~any(cellfun(@iscell,model.subSystems)) +0587 if ~any(~cellfun(@isempty,model.subSystems)) +0588 subSystems = {}; +0589 else +0590 subSystems = setdiff(model.subSystems,''); +0591 end +0592 else +0593 orderedSubs = cellfun(@(x) columnVector(x),model.subSystems,'UniformOUtput',false); +0594 subSystems = setdiff(vertcat(orderedSubs{:}),''); +0595 end +0596 if isempty(subSystems) +0597 subSystems = {}; +0598 end +0599 if ~isempty(subSystems) +0600 %Build the groups for the group package +0601 groupIDs = strcat('group',cellfun(@num2str, num2cell(1:length(subSystems)),'UniformOutput',false)); +0602 for i = 1:length(subSystems) +0603 cgroup = tmpStruct; +0604 if ~any(cellfun(@iscell,model.subSystems)) +0605 present = ismember(model.subSystems,subSystems{i}); +0606 else +0607 present = cellfun(@(x) any(ismember(x,subSystems{i})),model.subSystems); +0608 end +0609 groupMembers = rxns(present); +0610 for j = 1:numel(groupMembers) +0611 cMember = tmpStruct.groups_member; +0612 cMember.groups_idRef = groupMembers{j}; +0613 if j == 1 +0614 cgroup.groups_member = cMember; +0615 else +0616 cgroup.groups_member(j) = cMember; +0617 end +0618 end +0619 cgroup.groups_id = groupIDs{i}; +0620 cgroup.groups_name = subSystems{i}; +0621 if i == 1 +0622 modelSBML.groups_group = cgroup; +0623 else +0624 modelSBML.groups_group(i) = cgroup; +0625 end +0626 end +0627 end +0628 end +0629 +0630 %Prepare fbc_objective subfield +0631 +0632 modelSBML.fbc_objective.fbc_type='maximize'; +0633 modelSBML.fbc_objective.fbc_id='obj'; +0634 +0635 ind=find(model.c); +0636 +0637 if isempty(ind) +0638 modelSBML.fbc_objective.fbc_fluxObjective.fbc_coefficient=0; +0639 EM='The objective function is not defined. The model will be exported as it is. Notice that having undefined objective function may produce warnings related to "fbc:coefficient" and "fbc:reaction" in SBML Validator'; +0640 dispEM(EM,false); +0641 else +0642 for i=1:length(ind) +0643 %Copy the default values to the next index as long as it is not the +0644 %last one +0645 if i<numel(ind) +0646 modelSBML.reaction(i+1)=modelSBML.reaction(i); +0647 end +0648 values=model.c(model.c~=0); +0649 modelSBML.fbc_objective(i).fbc_fluxObjective.fbc_reaction=modelSBML.reaction(ind(i)).id; +0650 modelSBML.fbc_objective(i).fbc_fluxObjective.fbc_coefficient=values(i); +0651 modelSBML.fbc_objective(i).fbc_fluxObjective.isSetfbc_coefficient=1; +0652 end +0653 end +0654 +0655 modelSBML.fbc_activeObjective=modelSBML.fbc_objective.fbc_id; +0656 +0657 fbcStr=['http://www.sbml.org/sbml/level', num2str(sbmlLevel), '/version', num2str(sbmlVersion), '/fbc/version',num2str(sbmlPackageVersions(1))]; +0658 if modelHasSubsystems +0659 groupStr=['http://www.sbml.org/sbml/level', num2str(sbmlLevel), '/version', num2str(sbmlVersion), '/groups/version',num2str(sbmlPackageVersions(2))]; +0660 modelSBML.namespaces=struct('prefix',{'','fbc','groups'},... +0661 'uri',{['http://www.sbml.org/sbml/level', num2str(sbmlLevel), '/version', num2str(sbmlVersion), '/core'],... +0662 fbcStr,groupStr}); +0663 else +0664 modelSBML.namespaces=struct('prefix',{'','fbc'},... +0665 'uri',{['http://www.sbml.org/sbml/level', num2str(sbmlLevel), '/version', num2str(sbmlVersion), '/core'],... +0666 fbcStr}); +0667 end +0668 +0669 if sbmlPackageVersions(1) == 2 +0670 modelSBML.fbc_strict=1; +0671 end +0672 +0673 modelSBML.rule=[]; +0674 modelSBML.constraint=[]; 0675 -0676 sbmlFieldNames=getStructureFieldnames('model',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0677 sbmlDefaultValues=getDefaultValues('model',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0676 OutputSBML(modelSBML,fileName,1,0,[1,0]); +0677 end 0678 -0679 for i=1:numel(sbmlFieldNames) -0680 modelSBML.(sbmlFieldNames{1,i})=sbmlDefaultValues{1,i}; -0681 sbmlSubfieldNames=getStructureFieldnames(sbmlFieldNames{1,i},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0682 sbmlSubfieldValues=getDefaultValues(sbmlFieldNames{1,i},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0683 if ~strcmp(sbmlFieldNames{1,i},'event') && ~strcmp(sbmlFieldNames{1,i},'functionDefinition') && ~strcmp(sbmlFieldNames{1,i},'initialAssignment') -0684 for j=1:numel(sbmlSubfieldNames) -0685 modelSBML.(sbmlFieldNames{1,i}).(sbmlSubfieldNames{1,j})=sbmlSubfieldValues{1,j}; -0686 sbmlSubsubfieldNames=getStructureFieldnames(sbmlSubfieldNames{1,j},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0687 sbmlSubsubfieldValues=getDefaultValues(sbmlSubfieldNames{1,j},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0688 if ~strcmp(sbmlSubfieldNames{1,j},'modifier') && ~strcmp(sbmlSubfieldNames{1,j},'kineticLaw') -0689 for k=1:numel(sbmlSubsubfieldNames) -0690 %'compartment' and 'species' fields are not supposed to -0691 %have their standalone structures if they are subfields -0692 %or subsubfields -0693 if ~strcmp(sbmlSubfieldNames{1,j},'compartment') && ~strcmp(sbmlSubfieldNames{1,j},'species') -0694 modelSBML.(sbmlFieldNames{1,i}).(sbmlSubfieldNames{1,j}).(sbmlSubsubfieldNames{1,k})=sbmlSubsubfieldValues{1,k}; -0695 end -0696 %If it is fbc_association in the third level, we need -0697 %to establish the fourth level, since libSBML requires -0698 %it -0699 if strcmp(sbmlSubsubfieldNames{1,k},'fbc_association') -0700 fbc_associationFieldNames=getStructureFieldnames('fbc_association',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0701 fbc_associationFieldValues=getDefaultValues('fbc_association',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0702 for l=1:numel(fbc_associationFieldNames) -0703 modelSBML.(sbmlFieldNames{1,i}).(sbmlSubfieldNames{1,j}).(sbmlSubsubfieldNames{1,k}).(fbc_associationFieldNames{1,l})=fbc_associationFieldValues{1,l}; -0704 end -0705 end -0706 end -0707 end -0708 end -0709 end -0710 if ~isstruct(modelSBML.(sbmlFieldNames{1,i})) -0711 modelSBML.(sbmlFieldNames{1,i})=sbmlDefaultValues{1,i}; -0712 end -0713 end -0714 -0715 modelSBML.unitDefinition.id='mmol_per_gDW_per_hr'; -0716 -0717 unitFieldNames=getStructureFieldnames('unit',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0718 unitDefaultValues=getDefaultValues('unit',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); -0719 -0720 kinds={'mole','gram','second'}; -0721 exponents=[1 -1 -1]; -0722 scales=[-3 0 0]; -0723 multipliers=[1 1 1*60*60]; +0679 +0680 function modelSBML=getSBMLStructure(sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions) +0681 %Returns the blank SBML model structure by using appropriate libSBML +0682 %functions. This creates structure by considering three levels +0683 +0684 sbmlFieldNames=getStructureFieldnames('model',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0685 sbmlDefaultValues=getDefaultValues('model',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0686 +0687 for i=1:numel(sbmlFieldNames) +0688 modelSBML.(sbmlFieldNames{1,i})=sbmlDefaultValues{1,i}; +0689 sbmlSubfieldNames=getStructureFieldnames(sbmlFieldNames{1,i},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0690 sbmlSubfieldValues=getDefaultValues(sbmlFieldNames{1,i},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0691 if ~strcmp(sbmlFieldNames{1,i},'event') && ~strcmp(sbmlFieldNames{1,i},'functionDefinition') && ~strcmp(sbmlFieldNames{1,i},'initialAssignment') +0692 for j=1:numel(sbmlSubfieldNames) +0693 modelSBML.(sbmlFieldNames{1,i}).(sbmlSubfieldNames{1,j})=sbmlSubfieldValues{1,j}; +0694 sbmlSubsubfieldNames=getStructureFieldnames(sbmlSubfieldNames{1,j},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0695 sbmlSubsubfieldValues=getDefaultValues(sbmlSubfieldNames{1,j},sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0696 if ~strcmp(sbmlSubfieldNames{1,j},'modifier') && ~strcmp(sbmlSubfieldNames{1,j},'kineticLaw') +0697 for k=1:numel(sbmlSubsubfieldNames) +0698 %'compartment' and 'species' fields are not supposed to +0699 %have their standalone structures if they are subfields +0700 %or subsubfields +0701 if ~strcmp(sbmlSubfieldNames{1,j},'compartment') && ~strcmp(sbmlSubfieldNames{1,j},'species') +0702 modelSBML.(sbmlFieldNames{1,i}).(sbmlSubfieldNames{1,j}).(sbmlSubsubfieldNames{1,k})=sbmlSubsubfieldValues{1,k}; +0703 end +0704 %If it is fbc_association in the third level, we need +0705 %to establish the fourth level, since libSBML requires +0706 %it +0707 if strcmp(sbmlSubsubfieldNames{1,k},'fbc_association') +0708 fbc_associationFieldNames=getStructureFieldnames('fbc_association',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0709 fbc_associationFieldValues=getDefaultValues('fbc_association',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0710 for l=1:numel(fbc_associationFieldNames) +0711 modelSBML.(sbmlFieldNames{1,i}).(sbmlSubfieldNames{1,j}).(sbmlSubsubfieldNames{1,k}).(fbc_associationFieldNames{1,l})=fbc_associationFieldValues{1,l}; +0712 end +0713 end +0714 end +0715 end +0716 end +0717 end +0718 if ~isstruct(modelSBML.(sbmlFieldNames{1,i})) +0719 modelSBML.(sbmlFieldNames{1,i})=sbmlDefaultValues{1,i}; +0720 end +0721 end +0722 +0723 modelSBML.unitDefinition.id='mmol_per_gDW_per_hr'; 0724 -0725 for i=1:numel(unitFieldNames) -0726 modelSBML.unitDefinition.unit(1).(unitFieldNames{1,i})=unitDefaultValues{1,i}; -0727 for j=1:3 -0728 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=unitDefaultValues{1,i}; -0729 if strcmp(unitFieldNames{1,i},'kind') -0730 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=kinds{j}; -0731 elseif strcmp(unitFieldNames{1,i},'exponent') -0732 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=exponents(j); -0733 elseif strcmp(unitFieldNames{1,i},'scale') -0734 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=scales(j); -0735 elseif strcmp(unitFieldNames{1,i},'multiplier') -0736 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=multipliers(j); -0737 end -0738 end -0739 end -0740 end -0741 -0742 function miriamString=getMiriam(miriamStruct) -0743 %Returns a string with list elements for a miriam structure ('<rdf:li -0744 %rdf:resource="https://identifiers.org/go/GO:0005739"/>' for example). This -0745 %is just to speed up things since this is done many times during the -0746 %exporting -0747 -0748 miriamString=''; -0749 if isfield(miriamStruct,'name') -0750 for i=1:numel(miriamStruct.name) -0751 miriamString=[miriamString '<rdf:li rdf:resource="https://identifiers.org/' miriamStruct.name{i} '/' miriamStruct.value{i} '"/>']; -0752 end -0753 end -0754 end +0725 unitFieldNames=getStructureFieldnames('unit',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0726 unitDefaultValues=getDefaultValues('unit',sbmlLevel,sbmlVersion,sbmlPackages,sbmlPackageVersions); +0727 +0728 kinds={'mole','gram','second'}; +0729 exponents=[1 -1 -1]; +0730 scales=[-3 0 0]; +0731 multipliers=[1 1 1*60*60]; +0732 +0733 for i=1:numel(unitFieldNames) +0734 modelSBML.unitDefinition.unit(1).(unitFieldNames{1,i})=unitDefaultValues{1,i}; +0735 for j=1:3 +0736 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=unitDefaultValues{1,i}; +0737 if strcmp(unitFieldNames{1,i},'kind') +0738 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=kinds{j}; +0739 elseif strcmp(unitFieldNames{1,i},'exponent') +0740 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=exponents(j); +0741 elseif strcmp(unitFieldNames{1,i},'scale') +0742 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=scales(j); +0743 elseif strcmp(unitFieldNames{1,i},'multiplier') +0744 modelSBML.unitDefinition.unit(j).(unitFieldNames{1,i})=multipliers(j); +0745 end +0746 end +0747 end +0748 end +0749 +0750 function miriamString=getMiriam(miriamStruct) +0751 %Returns a string with list elements for a miriam structure ('<rdf:li +0752 %rdf:resource="https://identifiers.org/go/GO:0005739"/>' for example). This +0753 %is just to speed up things since this is done many times during the +0754 %exporting 0755 -0756 function [tmp_Rxn]=addReactantsProducts(model,sbmlModel,i) -0757 %This function provides reactants and products for particular reaction. The -0758 %function was 'borrowed' from writeSBML in COBRA toolbox, lines 663-679 -0759 -0760 met_idx = find(model.S(:, i)); -0761 tmp_Rxn.product=[]; -0762 tmp_Rxn.reactant=[]; -0763 for j_met=1:size(met_idx,1) -0764 tmp_idx = met_idx(j_met,1); -0765 sbml_tmp_species_ref.species = sbmlModel.species(tmp_idx).id; -0766 met_stoich = model.S(tmp_idx, i); -0767 sbml_tmp_species_ref.stoichiometry = abs(met_stoich); -0768 sbml_tmp_species_ref.isSetStoichiometry=1; -0769 sbml_tmp_species_ref.constant=1; -0770 if (met_stoich > 0) -0771 tmp_Rxn.product = [ tmp_Rxn.product, sbml_tmp_species_ref ]; -0772 else -0773 tmp_Rxn.reactant = [ tmp_Rxn.reactant, sbml_tmp_species_ref]; -0774 end -0775 end -0776 end -0777 -0778 function vecT = columnVector(vec) -0779 % Code below taken from COBRA Toolbox under GNU General Public License v3.0 -0780 % license file in readme/GPL.MD. -0781 % -0782 % Converts a vector to a column vector -0783 % -0784 % USAGE: -0785 % -0786 % vecT = columnVector(vec) -0787 % -0788 % INPUT: -0789 % vec: a vector -0790 % -0791 % OUTPUT: -0792 % vecT: a column vector -0793 -0794 [n, m] = size(vec); -0795 -0796 if n < m -0797 vecT = vec'; -0798 else -0799 vecT = vec; -0800 end -0801 end

    +0756 miriamString=''; +0757 if isfield(miriamStruct,'name') +0758 for i=1:numel(miriamStruct.name) +0759 miriamString=[miriamString '<rdf:li rdf:resource="https://identifiers.org/' miriamStruct.name{i} '/' miriamStruct.value{i} '"/>']; +0760 end +0761 end +0762 end +0763 +0764 function [tmp_Rxn]=addReactantsProducts(model,sbmlModel,i) +0765 %This function provides reactants and products for particular reaction. The +0766 %function was 'borrowed' from writeSBML in COBRA toolbox, lines 663-679 +0767 +0768 met_idx = find(model.S(:, i)); +0769 tmp_Rxn.product=[]; +0770 tmp_Rxn.reactant=[]; +0771 for j_met=1:size(met_idx,1) +0772 tmp_idx = met_idx(j_met,1); +0773 sbml_tmp_species_ref.species = sbmlModel.species(tmp_idx).id; +0774 met_stoich = model.S(tmp_idx, i); +0775 sbml_tmp_species_ref.stoichiometry = abs(met_stoich); +0776 sbml_tmp_species_ref.isSetStoichiometry=1; +0777 sbml_tmp_species_ref.constant=1; +0778 if (met_stoich > 0) +0779 tmp_Rxn.product = [ tmp_Rxn.product, sbml_tmp_species_ref ]; +0780 else +0781 tmp_Rxn.reactant = [ tmp_Rxn.reactant, sbml_tmp_species_ref]; +0782 end +0783 end +0784 end +0785 +0786 function vecT = columnVector(vec) +0787 % Code below taken from COBRA Toolbox under GNU General Public License v3.0 +0788 % license file in readme/GPL.MD. +0789 % +0790 % Converts a vector to a column vector +0791 % +0792 % USAGE: +0793 % +0794 % vecT = columnVector(vec) +0795 % +0796 % INPUT: +0797 % vec: a vector +0798 % +0799 % OUTPUT: +0800 % vecT: a column vector +0801 +0802 [n, m] = size(vec); +0803 +0804 if n < m +0805 vecT = vec'; +0806 else +0807 vecT = vec; +0808 end +0809 end

    Generated by m2html © 2005
    \ No newline at end of file diff --git a/doc/io/exportToExcelFormat.html b/doc/io/exportToExcelFormat.html index df284072..be859c81 100644 --- a/doc/io/exportToExcelFormat.html +++ b/doc/io/exportToExcelFormat.html @@ -24,7 +24,7 @@

    PURPOSE ^exportToExcelFormat

    SYNOPSIS ^

    -
    function exportToExcelFormat(model,filename)
    +
    function exportToExcelFormat(model,filename,sortIds)

    DESCRIPTION ^

     exportToExcelFormat
    @@ -36,6 +36,9 @@ 

    DESCRIPTION ^DESCRIPTION ^CROSS-REFERENCE INFORMATION ^

    This function calls: +
  • exportToTabDelimited exportToTabDelimited
  • loadWorkbook loadWorkbook
  • sortIdentifiers exportModel
  • writeSheet writeSheet
  • This function is called by: @@ -58,7 +61,7 @@

    CROSS-REFERENCE INFORMATION ^
 
 
 <h2><a name=SOURCE CODE ^

    -
    0001 function exportToExcelFormat(model,filename)
    +
    0001 function exportToExcelFormat(model,filename,sortIds)
     0002 % exportToExcelFormat
     0003 %   Exports a model structure to the Microsoft Excel model format
     0004 %
    @@ -68,369 +71,378 @@ 

    SOURCE CODE ^% be only a path, in which case the model is exported to a set 0009 % of tab-delimited text files instead. See exportToTabDelimited 0010 % for details regarding that functionality -0011 % -0012 % The resulting Excel file can be used with importExcelModel/SBMLFromExcel -0013 % for modelling or to generate a SBML file. +0011 % sortIds logical whether metabolites, reactions and genes should be +0012 % sorted alphabetically by their identifiers (opt, default +0013 % false) 0014 % -0015 % NOTE: No checks are made regarding the correctness of the model. Use -0016 % checkModelStruct to identify problems in the model structure +0015 % The resulting Excel file can be used with importExcelModel/SBMLFromExcel +0016 % for modelling or to generate a SBML file. 0017 % -0018 % Usage: exportToExcelFormat(model,filename) -0019 -0020 [~, A, B]=fileparts(filename); -0021 -0022 %If a path was used call on exportToTabDelimited instead -0023 if ~any(A) || ~any(B) -0024 exportToTabDelimited(model,filename); -0025 return; -0026 end -0027 -0028 if ~strcmpi(B,'.xlsx') -0029 EM='As of RAVEN version 1.9, only export to xlsx format is supported'; -0030 dispEM(EM); -0031 end -0032 -0033 import java.io.File; -0034 import java.io.FileOutputStream; -0035 import java.io.IOException; +0018 % NOTE: No checks are made regarding the correctness of the model. Use +0019 % checkModelStruct to identify problems in the model structure +0020 % +0021 % Usage: exportToExcelFormat(model,filename,sortIds) +0022 if nargin<3 +0023 sortIds=false; +0024 end +0025 if sortIds==true +0026 model=sortIdentifiers(model); +0027 end +0028 +0029 [~, A, B]=fileparts(filename); +0030 +0031 %If a path was used call on exportToTabDelimited instead +0032 if ~any(A) || ~any(B) +0033 exportToTabDelimited(model,filename); +0034 return; +0035 end 0036 -0037 %Remove the output file if it already exists -0038 if exist(filename,'file') -0039 delete(filename); +0037 if ~strcmpi(B,'.xlsx') +0038 EM='As of RAVEN version 1.9, only export to xlsx format is supported'; +0039 dispEM(EM); 0040 end 0041 -0042 %Load an empty workbook -0043 wb=loadWorkbook(filename,true); -0044 -0045 %Construct equations -0046 model.equations=constructEquations(model,model.rxns,true); -0047 -0048 %Check if it should print genes -0049 if isfield(model,'grRules') -0050 rules=model.grRules; -0051 else -0052 rules=[]; -0053 end -0054 -0055 %Check if the model has default upper/lower bounds. This determines if -0056 %those values should be printed or not -0057 hasDefaultLB=false; -0058 hasDefaultUB=false; -0059 if isfield(model,'annotation') -0060 if isfield(model.annotation,'defaultLB') -0061 hasDefaultLB=true; -0062 end -0063 if isfield(model.annotation,'defaultUB') -0064 hasDefaultUB=true; -0065 end -0066 end -0067 -0068 %Add the RXNS sheet -0069 -0070 %Create the header row -0071 headers={'#';'ID';'NAME';'EQUATION';'EC-NUMBER';'GENE ASSOCIATION';'LOWER BOUND';'UPPER BOUND';'OBJECTIVE';'COMPARTMENT';'MIRIAM';'SUBSYSTEM';'REPLACEMENT ID';'NOTE';'REFERENCE';'CONFIDENCE SCORE'}; -0072 -0073 %Add empty comments -0074 emptyColumn=cell(numel(model.rxns),1); -0075 rxnSheet=emptyColumn; +0042 import java.io.File; +0043 import java.io.FileOutputStream; +0044 import java.io.IOException; +0045 +0046 %Remove the output file if it already exists +0047 if exist(filename,'file') +0048 delete(filename); +0049 end +0050 +0051 %Load an empty workbook +0052 wb=loadWorkbook(filename,true); +0053 +0054 %Construct equations +0055 model.equations=constructEquations(model,model.rxns,true); +0056 +0057 %Check if it should print genes +0058 if isfield(model,'grRules') +0059 rules=model.grRules; +0060 else +0061 rules=[]; +0062 end +0063 +0064 %Check if the model has default upper/lower bounds. This determines if +0065 %those values should be printed or not +0066 hasDefaultLB=false; +0067 hasDefaultUB=false; +0068 if isfield(model,'annotation') +0069 if isfield(model.annotation,'defaultLB') +0070 hasDefaultLB=true; +0071 end +0072 if isfield(model.annotation,'defaultUB') +0073 hasDefaultUB=true; +0074 end +0075 end 0076 -0077 %Add the model fields -0078 rxnSheet=[rxnSheet model.rxns]; -0079 -0080 if isfield(model,'rxnNames') -0081 rxnSheet=[rxnSheet model.rxnNames]; -0082 else -0083 rxnSheet=[rxnSheet emptyColumn]; -0084 end +0077 %Add the RXNS sheet +0078 +0079 %Create the header row +0080 headers={'#';'ID';'NAME';'EQUATION';'EC-NUMBER';'GENE ASSOCIATION';'LOWER BOUND';'UPPER BOUND';'OBJECTIVE';'COMPARTMENT';'MIRIAM';'SUBSYSTEM';'REPLACEMENT ID';'NOTE';'REFERENCE';'CONFIDENCE SCORE'}; +0081 +0082 %Add empty comments +0083 emptyColumn=cell(numel(model.rxns),1); +0084 rxnSheet=emptyColumn; 0085 -0086 rxnSheet=[rxnSheet model.equations]; -0087 -0088 if isfield(model,'eccodes') -0089 rxnSheet=[rxnSheet model.eccodes]; -0090 else -0091 rxnSheet=[rxnSheet emptyColumn]; -0092 end -0093 -0094 if ~isempty(rules) -0095 rxnSheet=[rxnSheet rules]; -0096 else -0097 rxnSheet=[rxnSheet emptyColumn]; -0098 end -0099 -0100 lb=emptyColumn; -0101 ub=emptyColumn; -0102 objective=emptyColumn; -0103 rxnMiriams=emptyColumn; -0104 -0105 for i=1:numel(model.rxns) -0106 if isfield(model,'lb') -0107 if hasDefaultLB==true -0108 if model.rev(i)==1 -0109 %If reversible, print only if different than defaultLB -0110 if model.lb(i) ~= model.annotation.defaultLB -0111 lb{i}=model.lb(i); -0112 end -0113 else -0114 %If irreversible, print only for non-zero values -0115 if model.lb(i)~=0 -0116 lb{i}=model.lb(i); -0117 end -0118 end -0119 else -0120 lb{i}=model.lb(i); -0121 end -0122 end -0123 -0124 if isfield(model,'ub') -0125 if hasDefaultUB==true -0126 if model.ub(i) ~= model.annotation.defaultUB -0127 ub{i}=model.ub(i); -0128 end -0129 else -0130 ub{i}=model.ub(i); -0131 end -0132 end -0133 -0134 if isfield(model,'c') -0135 if model.c(i)~=0 -0136 objective{i}=model.c(i); -0137 end -0138 end -0139 -0140 if isfield(model,'rxnMiriams') -0141 if ~isempty(model.rxnMiriams{i}) -0142 toPrint=[]; -0143 for j=1:numel(model.rxnMiriams{i}.name) -0144 toPrint=[toPrint strtrim(model.rxnMiriams{i}.name{j}) '/' strtrim(model.rxnMiriams{i}.value{j}) ';']; -0145 end -0146 rxnMiriams{i}=toPrint(1:end-1); -0147 end -0148 end -0149 end -0150 -0151 rxnSheet=[rxnSheet lb]; -0152 rxnSheet=[rxnSheet ub]; -0153 rxnSheet=[rxnSheet objective]; -0154 -0155 if isfield(model,'rxnComps') -0156 rxnSheet=[rxnSheet model.comps(model.rxnComps)]; -0157 else -0158 rxnSheet=[rxnSheet emptyColumn]; -0159 end -0160 -0161 rxnSheet=[rxnSheet rxnMiriams]; -0162 -0163 subsystems=''; -0164 if isfield(model,'subSystems') -0165 for i=1:numel(model.subSystems) -0166 if ~isempty(model.subSystems{i,1}) -0167 subsystems{i,1}=strjoin(model.subSystems{i,1},';'); -0168 else -0169 subsystems{i,1}=''; -0170 end -0171 end -0172 rxnSheet=[rxnSheet subsystems]; -0173 else -0174 rxnSheet=[rxnSheet emptyColumn]; -0175 end -0176 -0177 %For REPLACEMENT ID which isn't in the model -0178 rxnSheet=[rxnSheet emptyColumn]; -0179 -0180 if isfield(model,'rxnNotes') -0181 rxnSheet=[rxnSheet model.rxnNotes]; +0086 %Add the model fields +0087 rxnSheet=[rxnSheet model.rxns]; +0088 +0089 if isfield(model,'rxnNames') +0090 rxnSheet=[rxnSheet model.rxnNames]; +0091 else +0092 rxnSheet=[rxnSheet emptyColumn]; +0093 end +0094 +0095 rxnSheet=[rxnSheet model.equations]; +0096 +0097 if isfield(model,'eccodes') +0098 rxnSheet=[rxnSheet model.eccodes]; +0099 else +0100 rxnSheet=[rxnSheet emptyColumn]; +0101 end +0102 +0103 if ~isempty(rules) +0104 rxnSheet=[rxnSheet rules]; +0105 else +0106 rxnSheet=[rxnSheet emptyColumn]; +0107 end +0108 +0109 lb=emptyColumn; +0110 ub=emptyColumn; +0111 objective=emptyColumn; +0112 rxnMiriams=emptyColumn; +0113 +0114 for i=1:numel(model.rxns) +0115 if isfield(model,'lb') +0116 if hasDefaultLB==true +0117 if model.rev(i)==1 +0118 %If reversible, print only if different than defaultLB +0119 if model.lb(i) ~= model.annotation.defaultLB +0120 lb{i}=model.lb(i); +0121 end +0122 else +0123 %If irreversible, print only for non-zero values +0124 if model.lb(i)~=0 +0125 lb{i}=model.lb(i); +0126 end +0127 end +0128 else +0129 lb{i}=model.lb(i); +0130 end +0131 end +0132 +0133 if isfield(model,'ub') +0134 if hasDefaultUB==true +0135 if model.ub(i) ~= model.annotation.defaultUB +0136 ub{i}=model.ub(i); +0137 end +0138 else +0139 ub{i}=model.ub(i); +0140 end +0141 end +0142 +0143 if isfield(model,'c') +0144 if model.c(i)~=0 +0145 objective{i}=model.c(i); +0146 end +0147 end +0148 +0149 if isfield(model,'rxnMiriams') +0150 if ~isempty(model.rxnMiriams{i}) +0151 toPrint=[]; +0152 for j=1:numel(model.rxnMiriams{i}.name) +0153 toPrint=[toPrint strtrim(model.rxnMiriams{i}.name{j}) '/' strtrim(model.rxnMiriams{i}.value{j}) ';']; +0154 end +0155 rxnMiriams{i}=toPrint(1:end-1); +0156 end +0157 end +0158 end +0159 +0160 rxnSheet=[rxnSheet lb]; +0161 rxnSheet=[rxnSheet ub]; +0162 rxnSheet=[rxnSheet objective]; +0163 +0164 if isfield(model,'rxnComps') +0165 rxnSheet=[rxnSheet model.comps(model.rxnComps)]; +0166 else +0167 rxnSheet=[rxnSheet emptyColumn]; +0168 end +0169 +0170 rxnSheet=[rxnSheet rxnMiriams]; +0171 +0172 subsystems=''; +0173 if isfield(model,'subSystems') +0174 for i=1:numel(model.subSystems) +0175 if ~isempty(model.subSystems{i,1}) +0176 subsystems{i,1}=strjoin(model.subSystems{i,1},';'); +0177 else +0178 subsystems{i,1}=''; +0179 end +0180 end +0181 rxnSheet=[rxnSheet subsystems]; 0182 else 0183 rxnSheet=[rxnSheet emptyColumn]; 0184 end 0185 -0186 if isfield(model,'rxnReferences') -0187 rxnSheet=[rxnSheet model.rxnReferences]; -0188 else -0189 rxnSheet=[rxnSheet emptyColumn]; -0190 end -0191 -0192 if isfield(model,'rxnConfidenceScores') -0193 rxnSheet=[rxnSheet num2cell(model.rxnConfidenceScores)]; -0194 else -0195 rxnSheet=[rxnSheet emptyColumn]; -0196 end -0197 -0198 wb=writeSheet(wb,'RXNS',0,headers,[],rxnSheet); -0199 -0200 headers={'#';'ID';'NAME';'UNCONSTRAINED';'MIRIAM';'COMPOSITION';'InChI';'COMPARTMENT';'REPLACEMENT ID';'CHARGE'}; -0201 -0202 metSheet=cell(numel(model.mets),numel(headers)); -0203 -0204 for i=1:numel(model.mets) -0205 metSheet{i,2}=[model.metNames{i} '[' model.comps{model.metComps(i)} ']']; -0206 -0207 if isfield(model,'metNames') -0208 metSheet(i,3)=model.metNames(i); -0209 end -0210 -0211 if isfield(model,'unconstrained') -0212 if model.unconstrained(i)~=0 -0213 metSheet{i,4}=true; -0214 end -0215 end -0216 -0217 if isfield(model,'metMiriams') -0218 if ~isempty(model.metMiriams{i}) -0219 toPrint=[]; -0220 for j=1:numel(model.metMiriams{i}.name) -0221 toPrint=[toPrint strtrim(model.metMiriams{i}.name{j}) '/' strtrim(model.metMiriams{i}.value{j}) ';']; -0222 end -0223 metSheet{i,5}=toPrint(1:end-1); -0224 end -0225 end -0226 -0227 % Making sure that only these metFormulas are exported, which don't -0228 % have InChI strings -0229 if isfield(model,'metFormulas') -0230 if isfield(model,'inchis') -0231 if isempty(model.inchis{i}) -0232 metSheet(i,6)=model.metFormulas(i); -0233 end -0234 else -0235 metSheet(i,6)=model.metFormulas(i); -0236 end -0237 end -0238 -0239 if isfield(model,'inchis') -0240 metSheet(i,7)=model.inchis(i); -0241 end -0242 -0243 if isfield(model,'metComps') -0244 metSheet(i,8)=model.comps(model.metComps(i)); -0245 end -0246 -0247 metSheet(i,9)=model.mets(i); -0248 -0249 if isfield(model,'metCharges') -0250 metSheet{i,10}=model.metCharges(i); -0251 end -0252 end -0253 -0254 wb=writeSheet(wb,'METS',1,headers,[],metSheet); -0255 -0256 %Add the COMPS sheet -0257 -0258 %Create the header row -0259 headers={'#';'ABBREVIATION';'NAME';'INSIDE';'MIRIAM'}; -0260 -0261 compSheet=cell(numel(model.comps),numel(headers)); +0186 %For REPLACEMENT ID which isn't in the model +0187 rxnSheet=[rxnSheet emptyColumn]; +0188 +0189 if isfield(model,'rxnNotes') +0190 rxnSheet=[rxnSheet model.rxnNotes]; +0191 else +0192 rxnSheet=[rxnSheet emptyColumn]; +0193 end +0194 +0195 if isfield(model,'rxnReferences') +0196 rxnSheet=[rxnSheet model.rxnReferences]; +0197 else +0198 rxnSheet=[rxnSheet emptyColumn]; +0199 end +0200 +0201 if isfield(model,'rxnConfidenceScores') +0202 rxnSheet=[rxnSheet num2cell(model.rxnConfidenceScores)]; +0203 else +0204 rxnSheet=[rxnSheet emptyColumn]; +0205 end +0206 +0207 wb=writeSheet(wb,'RXNS',0,headers,[],rxnSheet); +0208 +0209 headers={'#';'ID';'NAME';'UNCONSTRAINED';'MIRIAM';'COMPOSITION';'InChI';'COMPARTMENT';'REPLACEMENT ID';'CHARGE'}; +0210 +0211 metSheet=cell(numel(model.mets),numel(headers)); +0212 +0213 for i=1:numel(model.mets) +0214 metSheet{i,2}=[model.metNames{i} '[' model.comps{model.metComps(i)} ']']; +0215 +0216 if isfield(model,'metNames') +0217 metSheet(i,3)=model.metNames(i); +0218 end +0219 +0220 if isfield(model,'unconstrained') +0221 if model.unconstrained(i)~=0 +0222 metSheet{i,4}=true; +0223 end +0224 end +0225 +0226 if isfield(model,'metMiriams') +0227 if ~isempty(model.metMiriams{i}) +0228 toPrint=[]; +0229 for j=1:numel(model.metMiriams{i}.name) +0230 toPrint=[toPrint strtrim(model.metMiriams{i}.name{j}) '/' strtrim(model.metMiriams{i}.value{j}) ';']; +0231 end +0232 metSheet{i,5}=toPrint(1:end-1); +0233 end +0234 end +0235 +0236 % Making sure that only these metFormulas are exported, which don't +0237 % have InChI strings +0238 if isfield(model,'metFormulas') +0239 if isfield(model,'inchis') +0240 if isempty(model.inchis{i}) +0241 metSheet(i,6)=model.metFormulas(i); +0242 end +0243 else +0244 metSheet(i,6)=model.metFormulas(i); +0245 end +0246 end +0247 +0248 if isfield(model,'inchis') +0249 metSheet(i,7)=model.inchis(i); +0250 end +0251 +0252 if isfield(model,'metComps') +0253 metSheet(i,8)=model.comps(model.metComps(i)); +0254 end +0255 +0256 metSheet(i,9)=model.mets(i); +0257 +0258 if isfield(model,'metCharges') +0259 metSheet{i,10}=model.metCharges(i); +0260 end +0261 end 0262 -0263 for i=1:numel(model.comps) -0264 compSheet(i,2)=model.comps(i); -0265 -0266 if isfield(model,'compNames') -0267 compSheet(i,3)=model.compNames(i); -0268 end -0269 -0270 if isfield(model,'compOutside') -0271 compSheet(i,4)=model.compOutside(i); -0272 end -0273 -0274 if isfield(model,'compMiriams') -0275 if ~isempty(model.compMiriams{i}) -0276 toPrint=[]; -0277 for j=1:numel(model.compMiriams{i}.name) -0278 toPrint=[toPrint strtrim(model.compMiriams{i}.name{j}) '/' strtrim(model.compMiriams{i}.value{j}) ';']; -0279 end -0280 compSheet{i,5}=toPrint(1:end-1); -0281 end -0282 end -0283 end -0284 -0285 wb=writeSheet(wb,'COMPS',2,headers,[],compSheet); -0286 -0287 %Add the GENES sheet -0288 if isfield(model,'genes') -0289 %Create the header row -0290 headers={'#';'NAME';'MIRIAM';'SHORT NAME';'COMPARTMENT'}; -0291 -0292 geneSheet=cell(numel(model.genes),numel(headers)); -0293 -0294 for i=1:numel(model.genes) -0295 geneSheet(i,2)=model.genes(i); -0296 -0297 if isfield(model,'geneMiriams') -0298 if ~isempty(model.geneMiriams{i}) -0299 toPrint=[]; -0300 for j=1:numel(model.geneMiriams{i}.name) -0301 toPrint=[toPrint strtrim(model.geneMiriams{i}.name{j}) '/' strtrim(model.geneMiriams{i}.value{j}) ';']; -0302 end -0303 geneSheet{i,3}=toPrint(1:end-1); -0304 end -0305 end -0306 if isfield(model,'geneShortNames') -0307 geneSheet(i,4)=model.geneShortNames(i); -0308 end -0309 if isfield(model,'geneComps') -0310 geneSheet(i,5)=model.comps(model.geneComps(i)); -0311 end -0312 end -0313 -0314 wb=writeSheet(wb,'GENES',3,headers,[],geneSheet); -0315 end -0316 -0317 %Add the MODEL sheet -0318 -0319 %Create the header row -0320 headers={'#';'ID';'NAME';'TAXONOMY';'DEFAULT LOWER';'DEFAULT UPPER';'CONTACT GIVEN NAME';'CONTACT FAMILY NAME';'CONTACT EMAIL';'ORGANIZATION';'NOTES'}; -0321 -0322 modelSheet=cell(1,numel(headers)); -0323 -0324 if ~isfield(model,'annotation') -0325 model.annotation = []; -0326 end +0263 wb=writeSheet(wb,'METS',1,headers,[],metSheet); +0264 +0265 %Add the COMPS sheet +0266 +0267 %Create the header row +0268 headers={'#';'ABBREVIATION';'NAME';'INSIDE';'MIRIAM'}; +0269 +0270 compSheet=cell(numel(model.comps),numel(headers)); +0271 +0272 for i=1:numel(model.comps) +0273 compSheet(i,2)=model.comps(i); +0274 +0275 if isfield(model,'compNames') +0276 compSheet(i,3)=model.compNames(i); +0277 end +0278 +0279 if isfield(model,'compOutside') +0280 compSheet(i,4)=model.compOutside(i); +0281 end +0282 +0283 if isfield(model,'compMiriams') +0284 if ~isempty(model.compMiriams{i}) +0285 toPrint=[]; +0286 for j=1:numel(model.compMiriams{i}.name) +0287 toPrint=[toPrint strtrim(model.compMiriams{i}.name{j}) '/' strtrim(model.compMiriams{i}.value{j}) ';']; +0288 end +0289 compSheet{i,5}=toPrint(1:end-1); +0290 end +0291 end +0292 end +0293 +0294 wb=writeSheet(wb,'COMPS',2,headers,[],compSheet); +0295 +0296 %Add the GENES sheet +0297 if isfield(model,'genes') +0298 %Create the header row +0299 headers={'#';'NAME';'MIRIAM';'SHORT NAME';'COMPARTMENT'}; +0300 +0301 geneSheet=cell(numel(model.genes),numel(headers)); +0302 +0303 for i=1:numel(model.genes) +0304 geneSheet(i,2)=model.genes(i); +0305 +0306 if isfield(model,'geneMiriams') +0307 if ~isempty(model.geneMiriams{i}) +0308 toPrint=[]; +0309 for j=1:numel(model.geneMiriams{i}.name) +0310 toPrint=[toPrint strtrim(model.geneMiriams{i}.name{j}) '/' strtrim(model.geneMiriams{i}.value{j}) ';']; +0311 end +0312 geneSheet{i,3}=toPrint(1:end-1); +0313 end +0314 end +0315 if isfield(model,'geneShortNames') +0316 geneSheet(i,4)=model.geneShortNames(i); +0317 end +0318 if isfield(model,'geneComps') +0319 geneSheet(i,5)=model.comps(model.geneComps(i)); +0320 end +0321 end +0322 +0323 wb=writeSheet(wb,'GENES',3,headers,[],geneSheet); +0324 end +0325 +0326 %Add the MODEL sheet 0327 -0328 if isfield(model,'id') -0329 modelSheet{1,2}=model.id; -0330 else -0331 modelSheet{1,2}='blankID'; -0332 end -0333 if isfield(model,'name') -0334 modelSheet{1,3}=model.name; -0335 else -0336 modelSheet{1,3}='blankName'; -0337 end -0338 if isfield(model.annotation,'taxonomy') -0339 modelSheet{1,4}=model.annotation.taxonomy; -0340 end -0341 if isfield(model.annotation,'defaultLB') -0342 modelSheet{1,5}=model.annotation.defaultLB; -0343 end -0344 if isfield(model.annotation,'defaultUB') -0345 modelSheet{1,6}=model.annotation.defaultUB; +0328 %Create the header row +0329 headers={'#';'ID';'NAME';'TAXONOMY';'DEFAULT LOWER';'DEFAULT UPPER';'CONTACT GIVEN NAME';'CONTACT FAMILY NAME';'CONTACT EMAIL';'ORGANIZATION';'NOTES'}; +0330 +0331 modelSheet=cell(1,numel(headers)); +0332 +0333 if ~isfield(model,'annotation') +0334 model.annotation = []; +0335 end +0336 +0337 if isfield(model,'id') +0338 modelSheet{1,2}=model.id; +0339 else +0340 modelSheet{1,2}='blankID'; +0341 end +0342 if isfield(model,'name') +0343 modelSheet{1,3}=model.name; +0344 else +0345 modelSheet{1,3}='blankName'; 0346 end -0347 if isfield(model.annotation,'givenName') -0348 modelSheet{1,7}=model.annotation.givenName; +0347 if isfield(model.annotation,'taxonomy') +0348 modelSheet{1,4}=model.annotation.taxonomy; 0349 end -0350 if isfield(model.annotation,'familyName') -0351 modelSheet{1,8}=model.annotation.familyName; +0350 if isfield(model.annotation,'defaultLB') +0351 modelSheet{1,5}=model.annotation.defaultLB; 0352 end -0353 if isfield(model.annotation,'email') -0354 modelSheet{1,9}=model.annotation.email; +0353 if isfield(model.annotation,'defaultUB') +0354 modelSheet{1,6}=model.annotation.defaultUB; 0355 end -0356 if isfield(model.annotation,'organization') -0357 modelSheet{1,10}=model.annotation.organization; +0356 if isfield(model.annotation,'givenName') +0357 modelSheet{1,7}=model.annotation.givenName; 0358 end -0359 if isfield(model.annotation,'note') -0360 modelSheet{1,11}=model.annotation.note; +0359 if isfield(model.annotation,'familyName') +0360 modelSheet{1,8}=model.annotation.familyName; 0361 end -0362 -0363 if isfield(model,'genes') -0364 wb=writeSheet(wb,'MODEL',4,headers,[],modelSheet); -0365 else -0366 wb=writeSheet(wb,'MODEL',3,headers,[],modelSheet); +0362 if isfield(model.annotation,'email') +0363 modelSheet{1,9}=model.annotation.email; +0364 end +0365 if isfield(model.annotation,'organization') +0366 modelSheet{1,10}=model.annotation.organization; 0367 end -0368 -0369 %Open the output stream -0370 out = FileOutputStream(filename); -0371 wb.write(out); -0372 out.close(); -0373 end

    +0368 if isfield(model.annotation,'note') +0369 modelSheet{1,11}=model.annotation.note; +0370 end +0371 +0372 if isfield(model,'genes') +0373 wb=writeSheet(wb,'MODEL',4,headers,[],modelSheet); +0374 else +0375 wb=writeSheet(wb,'MODEL',3,headers,[],modelSheet); +0376 end +0377 +0378 %Open the output stream +0379 out = FileOutputStream(filename); +0380 wb.write(out); +0381 out.close(); +0382 end

    Generated by m2html © 2005
    \ No newline at end of file diff --git a/doc/io/exportToTabDelimited.html b/doc/io/exportToTabDelimited.html index b35d6ca0..d570724b 100644 --- a/doc/io/exportToTabDelimited.html +++ b/doc/io/exportToTabDelimited.html @@ -24,7 +24,7 @@

    PURPOSE ^exportToTabDelimited

    SYNOPSIS ^

    -
    function exportToTabDelimited(model,path)
    +
    function exportToTabDelimited(model,path,sortIds)

    DESCRIPTION ^

     exportToTabDelimited
    @@ -34,6 +34,8 @@ 

    DESCRIPTION ^DESCRIPTION ^CROSS-REFERENCE INFORMATION ^

    This function calls: +
  • sortIdentifiers exportModel
  • This function is called by: +
  • exportToExcelFormat exportToExcelFormat
  • SOURCE CODE ^

    -
    0001 function exportToTabDelimited(model,path)
    +
    0001 function exportToTabDelimited(model,path,sortIds)
     0002 % exportToTabDelimited
     0003 %   Exports a model structure to a set of tab-delimited text files
     0004 %
    @@ -65,330 +67,338 @@ 

    SOURCE CODE ^% path the path to export to. The resulting text files will be saved 0007 % under the names excelRxns.txt, excelMets.txt, excelGenes.txt, 0008 % excelModel.txt, and excelComps.txt -0009 % -0010 % NOTE: This functionality was previously a part of exportToExcelFormat. -0011 % The naming of the resulting text files is to preserve backward -0012 % compatibility -0013 % -0014 % NOTE: No checks are made regarding the correctness of the model. Use -0015 % checkModelStruct to identify problems in the model structure -0016 % -0017 % Usage: exportToTabDelimited(model,path) -0018 -0019 if nargin<2 -0020 path='./'; -0021 end -0022 -0023 %If the folder doesn't exist then create it -0024 if ~exist(path,'dir') -0025 mkdir(path); +0009 % sortIds logical whether metabolites, reactions and genes should be +0010 % sorted alphabetically by their identifiers (opt, default false) +0011 % +0012 % NOTE: This functionality was previously a part of exportToExcelFormat. +0013 % The naming of the resulting text files is to preserve backward +0014 % compatibility +0015 % +0016 % NOTE: No checks are made regarding the correctness of the model. Use +0017 % checkModelStruct to identify problems in the model structure +0018 % +0019 % Usage: exportToTabDelimited(model,path,sortIds) +0020 +0021 if nargin<2 +0022 path='./'; +0023 end +0024 if nargin<3 +0025 sortIds=false; 0026 end -0027 -0028 %Remove the files if they already exist -0029 if exist(fullfile(path,'excelRxns.txt'),'file') -0030 delete(fullfile(path,'excelRxns.txt')); -0031 end -0032 if exist(fullfile(path,'excelMets.txt'),'file') -0033 delete(fullfile(path,'excelMets.txt')); +0027 if sortIds==true +0028 model=sortIdentifiers(model); +0029 end +0030 +0031 %If the folder doesn't exist then create it +0032 if ~exist(path,'dir') +0033 mkdir(path); 0034 end -0035 if exist(fullfile(path,'excelGenes.txt'),'file') -0036 delete(fullfile(path,'excelGenes.txt')); -0037 end -0038 if exist(fullfile(path,'excelModel.txt'),'file') -0039 delete(fullfile(path,'excelModel.txt')); -0040 end -0041 if exist(fullfile(path,'excelComps.txt'),'file') -0042 delete(fullfile(path,'excelComps.txt')); -0043 end -0044 -0045 %Construct equations -0046 model.equations=constructEquations(model,model.rxns,true); -0047 -0048 %Open for printing the rxn sheet -0049 rxnFile=fopen(fullfile(path,'excelRxns.txt'),'wt'); -0050 -0051 %Print header -0052 fprintf(rxnFile,'#\tID\tNAME\tEQUATION\tEC-NUMBER\tGENE ASSOCIATION\tLOWER BOUND\tUPPER BOUND\tOBJECTIVE\tCOMPARTMENT\tMIRIAM\tSUBSYSTEM\tREPLACEMENT ID\tNOTE\tREFERENCE\tCONFIDENCE SCORE\n'); -0053 -0054 %Loop through the reactions -0055 for i=1:numel(model.rxns) -0056 fprintf(rxnFile,['\t' model.rxns{i} '\t' model.rxnNames{i} '\t' model.equations{i} '\t']); -0057 -0058 if isfield(model,'eccodes') -0059 fprintf(rxnFile,[model.eccodes{i} '\t']); -0060 else -0061 fprintf(rxnFile,'\t'); -0062 end -0063 -0064 if isfield(model,'grRules') -0065 fprintf(rxnFile,[model.grRules{i} '\t']); -0066 else -0067 fprintf(rxnFile,'\t'); -0068 end -0069 -0070 %Print bounds and objectives -0071 fprintf(rxnFile,[num2str(model.lb(i)) '\t' num2str(model.ub(i)) '\t']); -0072 -0073 if model.c(i)~=0 -0074 fprintf(rxnFile,[num2str(model.c(i)) '\t' ]); -0075 else -0076 fprintf(rxnFile,'\t'); -0077 end -0078 -0079 if isfield(model,'rxnComps') -0080 fprintf(rxnFile,[model.comps{model.rxnComps(i)} '\t']); -0081 else -0082 fprintf(rxnFile,'\t'); -0083 end -0084 -0085 if isfield(model,'rxnMiriams') -0086 if ~isempty(model.rxnMiriams{i}) -0087 toPrint=[]; -0088 for j=1:numel(model.rxnMiriams{i}.name) -0089 toPrint=[toPrint strtrim(model.rxnMiriams{i}.name{j}) '/' strtrim(model.rxnMiriams{i}.value{j}) ';']; -0090 end -0091 fprintf(rxnFile,[toPrint(1:end-1) '\t']); -0092 else -0093 fprintf(rxnFile,'\t'); -0094 end -0095 else -0096 fprintf(rxnFile,'\t'); -0097 end -0098 -0099 if isfield(model,'subSystems') -0100 if ~isempty(model.subSystems{i}) -0101 fprintf(rxnFile,[strjoin(model.subSystems{i,1},';') '\t']); -0102 else -0103 fprintf(rxnFile,'\t'); -0104 end +0035 +0036 %Remove the files if they already exist +0037 if exist(fullfile(path,'excelRxns.txt'),'file') +0038 delete(fullfile(path,'excelRxns.txt')); +0039 end +0040 if exist(fullfile(path,'excelMets.txt'),'file') +0041 delete(fullfile(path,'excelMets.txt')); +0042 end +0043 if exist(fullfile(path,'excelGenes.txt'),'file') +0044 delete(fullfile(path,'excelGenes.txt')); +0045 end +0046 if exist(fullfile(path,'excelModel.txt'),'file') +0047 delete(fullfile(path,'excelModel.txt')); +0048 end +0049 if exist(fullfile(path,'excelComps.txt'),'file') +0050 delete(fullfile(path,'excelComps.txt')); +0051 end +0052 +0053 %Construct equations +0054 model.equations=constructEquations(model,model.rxns,true); +0055 +0056 %Open for printing the rxn sheet +0057 rxnFile=fopen(fullfile(path,'excelRxns.txt'),'wt'); +0058 +0059 %Print header +0060 fprintf(rxnFile,'#\tID\tNAME\tEQUATION\tEC-NUMBER\tGENE ASSOCIATION\tLOWER BOUND\tUPPER BOUND\tOBJECTIVE\tCOMPARTMENT\tMIRIAM\tSUBSYSTEM\tREPLACEMENT ID\tNOTE\tREFERENCE\tCONFIDENCE SCORE\n'); +0061 +0062 %Loop through the reactions +0063 for i=1:numel(model.rxns) +0064 fprintf(rxnFile,['\t' model.rxns{i} '\t' model.rxnNames{i} '\t' model.equations{i} '\t']); +0065 +0066 if isfield(model,'eccodes') +0067 fprintf(rxnFile,[model.eccodes{i} '\t']); +0068 else +0069 fprintf(rxnFile,'\t'); +0070 end +0071 +0072 if isfield(model,'grRules') +0073 fprintf(rxnFile,[model.grRules{i} '\t']); +0074 else +0075 fprintf(rxnFile,'\t'); +0076 end +0077 +0078 %Print bounds and objectives +0079 fprintf(rxnFile,[num2str(model.lb(i)) '\t' num2str(model.ub(i)) '\t']); +0080 +0081 if model.c(i)~=0 +0082 fprintf(rxnFile,[num2str(model.c(i)) '\t' ]); +0083 else +0084 fprintf(rxnFile,'\t'); +0085 end +0086 +0087 if isfield(model,'rxnComps') +0088 fprintf(rxnFile,[model.comps{model.rxnComps(i)} '\t']); +0089 else +0090 fprintf(rxnFile,'\t'); +0091 end +0092 +0093 if isfield(model,'rxnMiriams') +0094 if ~isempty(model.rxnMiriams{i}) +0095 toPrint=[]; +0096 for j=1:numel(model.rxnMiriams{i}.name) +0097 toPrint=[toPrint strtrim(model.rxnMiriams{i}.name{j}) '/' strtrim(model.rxnMiriams{i}.value{j}) ';']; +0098 end +0099 fprintf(rxnFile,[toPrint(1:end-1) '\t']); +0100 else +0101 fprintf(rxnFile,'\t'); +0102 end +0103 else +0104 fprintf(rxnFile,'\t'); 0105 end 0106 -0107 %Print replacement IDs -0108 fprintf(rxnFile,'\t'); -0109 -0110 if isfield(model,'rxnNotes') -0111 fprintf(rxnFile,[model.rxnNotes{i} '\t']); -0112 else -0113 fprintf(rxnFile,'\t'); -0114 end -0115 -0116 if isfield(model,'rxnReferences') -0117 fprintf(rxnFile,[model.rxnReferences{i} '\t']); -0118 else -0119 fprintf(rxnFile,'\t'); -0120 end -0121 -0122 if isfield(model,'rxnConfidenceScores') -0123 fprintf(rxnFile,[num2str(model.rxnConfidenceScores(i)) '\t' ]); -0124 else -0125 fprintf(rxnFile,'\t'); -0126 end -0127 -0128 fprintf(rxnFile,'\n'); -0129 end -0130 -0131 fclose(rxnFile); -0132 -0133 %Open for printing the metabolites sheet -0134 metFile=fopen(fullfile(path,'excelMets.txt'),'wt'); -0135 -0136 %Print header -0137 fprintf(metFile,'#\tID\tNAME\tUNCONSTRAINED\tMIRIAM\tCOMPOSITION\tInChI\tCOMPARTMENT\tREPLACEMENT ID\tMETS FIELD\tCHARGE\n'); +0107 if isfield(model,'subSystems') +0108 if ~isempty(model.subSystems{i}) +0109 fprintf(rxnFile,[strjoin(model.subSystems{i,1},';') '\t']); +0110 else +0111 fprintf(rxnFile,'\t'); +0112 end +0113 end +0114 +0115 %Print replacement IDs +0116 fprintf(rxnFile,'\t'); +0117 +0118 if isfield(model,'rxnNotes') +0119 fprintf(rxnFile,[model.rxnNotes{i} '\t']); +0120 else +0121 fprintf(rxnFile,'\t'); +0122 end +0123 +0124 if isfield(model,'rxnReferences') +0125 fprintf(rxnFile,[model.rxnReferences{i} '\t']); +0126 else +0127 fprintf(rxnFile,'\t'); +0128 end +0129 +0130 if isfield(model,'rxnConfidenceScores') +0131 fprintf(rxnFile,[num2str(model.rxnConfidenceScores(i)) '\t' ]); +0132 else +0133 fprintf(rxnFile,'\t'); +0134 end +0135 +0136 fprintf(rxnFile,'\n'); +0137 end 0138 -0139 %Loop through the metabolites -0140 for i=1:numel(model.mets) -0141 fprintf(metFile,['\t' model.metNames{i} '[' model.comps{model.metComps(i)} ']\t' model.metNames{i} '\t']); -0142 -0143 if isfield(model,'unconstrained') -0144 if model.unconstrained(i)~=0 -0145 fprintf(metFile,'TRUE\t'); -0146 else -0147 fprintf(metFile,'\t'); -0148 end -0149 else -0150 fprintf(metFile,'\t'); -0151 end -0152 -0153 if isfield(model,'metMiriams') -0154 if ~isempty(model.metMiriams{i}) -0155 toPrint=[]; -0156 for j=1:numel(model.metMiriams{i}.name) -0157 toPrint=[toPrint strtrim(model.metMiriams{i}.name{j}) '/' strtrim(model.metMiriams{i}.value{j}) ';']; -0158 end -0159 fprintf(rxnFile,[toPrint(1:end-1) '\t']); -0160 else -0161 fprintf(metFile,'\t'); -0162 end -0163 else -0164 fprintf(metFile,'\t'); -0165 end -0166 -0167 if isfield(model,'metFormulas') -0168 fprintf(metFile,[model.metFormulas{i} '\t']); -0169 else -0170 fprintf(metFile,'\t'); -0171 end -0172 -0173 if isfield(model,'inchis') -0174 fprintf(metFile,[model.inchis{i} '\t']); -0175 else -0176 fprintf(metFile,'\t'); -0177 end -0178 -0179 fprintf(metFile,[model.comps{model.metComps(i)} '\t']); +0139 fclose(rxnFile); +0140 +0141 %Open for printing the metabolites sheet +0142 metFile=fopen(fullfile(path,'excelMets.txt'),'wt'); +0143 +0144 %Print header +0145 fprintf(metFile,'#\tID\tNAME\tUNCONSTRAINED\tMIRIAM\tCOMPOSITION\tInChI\tCOMPARTMENT\tREPLACEMENT ID\tMETS FIELD\tCHARGE\n'); +0146 +0147 %Loop through the metabolites +0148 for i=1:numel(model.mets) +0149 fprintf(metFile,['\t' model.metNames{i} '[' model.comps{model.metComps(i)} ']\t' model.metNames{i} '\t']); +0150 +0151 if isfield(model,'unconstrained') +0152 if model.unconstrained(i)~=0 +0153 fprintf(metFile,'TRUE\t'); +0154 else +0155 fprintf(metFile,'\t'); +0156 end +0157 else +0158 fprintf(metFile,'\t'); +0159 end +0160 +0161 if isfield(model,'metMiriams') +0162 if ~isempty(model.metMiriams{i}) +0163 toPrint=[]; +0164 for j=1:numel(model.metMiriams{i}.name) +0165 toPrint=[toPrint strtrim(model.metMiriams{i}.name{j}) '/' strtrim(model.metMiriams{i}.value{j}) ';']; +0166 end +0167 fprintf(rxnFile,[toPrint(1:end-1) '\t']); +0168 else +0169 fprintf(metFile,'\t'); +0170 end +0171 else +0172 fprintf(metFile,'\t'); +0173 end +0174 +0175 if isfield(model,'metFormulas') +0176 fprintf(metFile,[model.metFormulas{i} '\t']); +0177 else +0178 fprintf(metFile,'\t'); +0179 end 0180 -0181 %There can be no replacement IDs in the structure, but it has to be -0182 %something to give working met IDs. -0183 fprintf(metFile,['m' int2str(i) '\t']); -0184 -0185 %Print the model.mets field. The reason for not putting this as -0186 %replacement ID is that it's not guaranteed to be a valid SBML id. -0187 fprintf(metFile,[model.mets{i} '\t']); +0181 if isfield(model,'inchis') +0182 fprintf(metFile,[model.inchis{i} '\t']); +0183 else +0184 fprintf(metFile,'\t'); +0185 end +0186 +0187 fprintf(metFile,[model.comps{model.metComps(i)} '\t']); 0188 -0189 if isfield(model,'metCharges') -0190 fprintf(metFile,[num2str(model.metCharges(i)) '\t']); -0191 else -0192 fprintf(metFile,'\t'); -0193 end -0194 -0195 fprintf(metFile,'\n'); -0196 end -0197 -0198 fclose(metFile); -0199 -0200 if isfield(model,'genes') -0201 %Open for printing the genes sheet -0202 geneFile=fopen(fullfile(path,'excelGenes.txt'),'wt'); -0203 -0204 %Print header -0205 fprintf(geneFile,'#\tNAME\tMIRIAM\tSHORT NAME\tCOMPARTMENT\n'); -0206 -0207 %Loop through the genes -0208 for i=1:numel(model.genes) -0209 fprintf(geneFile,['\t' model.genes{i} '\t']); -0210 -0211 if isfield(model,'geneMiriams') -0212 if ~isempty(model.geneMiriams{i}) -0213 toPrint=[]; -0214 for j=1:numel(model.geneMiriams{i}.name) -0215 toPrint=[toPrint strtrim(model.geneMiriams{i}.name{j}) '/' strtrim(model.geneMiriams{i}.value{j}) ';']; -0216 end -0217 fprintf(geneFile,[toPrint(1:end-1) '\t']); -0218 else -0219 fprintf(geneFile,'\t'); -0220 end -0221 else -0222 fprintf(geneFile,'\t'); -0223 end -0224 -0225 if isfield(model,'geneShortNames') -0226 fprintf(geneFile,[model.geneShortNames{i} '\t']); -0227 else -0228 fprintf(geneFile,'\t'); -0229 end -0230 -0231 if isfield(model,'geneComps') -0232 fprintf(geneFile,[model.comps{model.geneComps(i)} '\t']); -0233 else -0234 fprintf(geneFile,'\t'); -0235 end -0236 -0237 fprintf(geneFile,'\n'); -0238 end -0239 fclose(geneFile); -0240 end -0241 -0242 if isfield(model,'id') -0243 %Open for printing the model sheet -0244 modelFile=fopen(fullfile(path,'excelModel.txt'),'wt'); -0245 -0246 %Print header -0247 fprintf(geneFile,'#\tID\tNAME\tDEFAULT LOWER\tDEFAULT UPPER\tCONTACT GIVEN NAME\tCONTACT FAMILY NAME\tCONTACT EMAIL\tORGANIZATION\tTAXONOMY\tNOTES\n'); -0248 -0249 %Print model ID and name. It is assumed that the default lower/upper -0250 %bound correspond to min/max of the bounds -0251 toPrint=['\t' model.id '\t' model.name '\t']; -0252 if isfield(model,'annotation') -0253 if isfield(model.annotation,'defaultLB') -0254 toPrint=[toPrint num2str(model.annotation.defaultLB) '\t']; -0255 else -0256 toPrint=[toPrint num2str(min(model.lb)) '\t']; -0257 end -0258 if isfield(model.annotation,'defaultUB') -0259 toPrint=[toPrint num2str(model.annotation.defaultUB) '\t']; -0260 else -0261 toPrint=[toPrint num2str(max(model.ub)) '\t']; -0262 end -0263 if isfield(model.annotation,'givenName') -0264 toPrint=[toPrint model.annotation.givenName '\t']; -0265 else -0266 toPrint=[toPrint '\t']; -0267 end -0268 if isfield(model.annotation,'familyName') -0269 toPrint=[toPrint model.annotation.familyName '\t']; -0270 else -0271 toPrint=[toPrint '\t']; -0272 end -0273 if isfield(model.annotation,'email') -0274 toPrint=[toPrint model.annotation.email '\t']; -0275 else -0276 toPrint=[toPrint '\t']; -0277 end -0278 if isfield(model.annotation,'organization') -0279 toPrint=[toPrint model.annotation.organization '\t']; -0280 else -0281 toPrint=[toPrint '\t']; -0282 end -0283 if isfield(model.annotation,'taxonomy') -0284 toPrint=[toPrint model.annotation.taxonomy '\t']; -0285 else -0286 toPrint=[toPrint '\t']; -0287 end -0288 if isfield(model.annotation,'note') -0289 toPrint=[toPrint model.annotation.note '\t']; -0290 else -0291 toPrint=[toPrint '\t']; -0292 end -0293 else -0294 toPrint=[toPrint num2str(min(model.lb)) '\t' num2str(max(model.ub)) '\t\t\t\t\t\t\n']; -0295 end -0296 fprintf(modelFile,toPrint); -0297 fclose(modelFile); -0298 end -0299 -0300 if isfield(model,'comps') -0301 %Open for printing the model sheet -0302 compsFile=fopen(fullfile(path,'excelComps.txt'),'wt'); -0303 -0304 %Print header -0305 fprintf(compsFile,'#\tABBREVIATION\tNAME\tINSIDE\tMIRIAM\n'); -0306 -0307 for i=1:numel(model.comps) -0308 toPrint=['\t' model.comps{i} '\t' model.compNames{i} '\t']; -0309 if isfield(model,'compOutside') -0310 toPrint=[toPrint model.compOutside{i} '\t']; -0311 else -0312 toPrint=[toPrint '\t']; -0313 end -0314 if isfield(model,'compMiriams') -0315 if ~isempty(model.compMiriams{i}) -0316 for j=1:numel(model.compMiriams{i}.name) -0317 toPrint=[toPrint strtrim(model.compMiriams{i}.name{j}) '/' strtrim(model.compMiriams{i}.value{j}) ';']; -0318 end -0319 toPrint(end)=[]; -0320 toPrint=[toPrint '\t']; -0321 else -0322 toPrint=[toPrint '\t']; -0323 end -0324 else -0325 toPrint=[toPrint '\t']; -0326 end -0327 toPrint=[toPrint '\n']; -0328 fprintf(compsFile,toPrint); -0329 end -0330 fclose(compsFile); -0331 end -0332 end

    +0189 %There can be no replacement IDs in the structure, but it has to be +0190 %something to give working met IDs. +0191 fprintf(metFile,['m' int2str(i) '\t']); +0192 +0193 %Print the model.mets field. The reason for not putting this as +0194 %replacement ID is that it's not guaranteed to be a valid SBML id. +0195 fprintf(metFile,[model.mets{i} '\t']); +0196 +0197 if isfield(model,'metCharges') +0198 fprintf(metFile,[num2str(model.metCharges(i)) '\t']); +0199 else +0200 fprintf(metFile,'\t'); +0201 end +0202 +0203 fprintf(metFile,'\n'); +0204 end +0205 +0206 fclose(metFile); +0207 +0208 if isfield(model,'genes') +0209 %Open for printing the genes sheet +0210 geneFile=fopen(fullfile(path,'excelGenes.txt'),'wt'); +0211 +0212 %Print header +0213 fprintf(geneFile,'#\tNAME\tMIRIAM\tSHORT NAME\tCOMPARTMENT\n'); +0214 +0215 %Loop through the genes +0216 for i=1:numel(model.genes) +0217 fprintf(geneFile,['\t' model.genes{i} '\t']); +0218 +0219 if isfield(model,'geneMiriams') +0220 if ~isempty(model.geneMiriams{i}) +0221 toPrint=[]; +0222 for j=1:numel(model.geneMiriams{i}.name) +0223 toPrint=[toPrint strtrim(model.geneMiriams{i}.name{j}) '/' strtrim(model.geneMiriams{i}.value{j}) ';']; +0224 end +0225 fprintf(geneFile,[toPrint(1:end-1) '\t']); +0226 else +0227 fprintf(geneFile,'\t'); +0228 end +0229 else +0230 fprintf(geneFile,'\t'); +0231 end +0232 +0233 if isfield(model,'geneShortNames') +0234 fprintf(geneFile,[model.geneShortNames{i} '\t']); +0235 else +0236 fprintf(geneFile,'\t'); +0237 end +0238 +0239 if isfield(model,'geneComps') +0240 fprintf(geneFile,[model.comps{model.geneComps(i)} '\t']); +0241 else +0242 fprintf(geneFile,'\t'); +0243 end +0244 +0245 fprintf(geneFile,'\n'); +0246 end +0247 fclose(geneFile); +0248 end +0249 +0250 if isfield(model,'id') +0251 %Open for printing the model sheet +0252 modelFile=fopen(fullfile(path,'excelModel.txt'),'wt'); +0253 +0254 %Print header +0255 fprintf(geneFile,'#\tID\tNAME\tDEFAULT LOWER\tDEFAULT UPPER\tCONTACT GIVEN NAME\tCONTACT FAMILY NAME\tCONTACT EMAIL\tORGANIZATION\tTAXONOMY\tNOTES\n'); +0256 +0257 %Print model ID and name. It is assumed that the default lower/upper +0258 %bound correspond to min/max of the bounds +0259 toPrint=['\t' model.id '\t' model.name '\t']; +0260 if isfield(model,'annotation') +0261 if isfield(model.annotation,'defaultLB') +0262 toPrint=[toPrint num2str(model.annotation.defaultLB) '\t']; +0263 else +0264 toPrint=[toPrint num2str(min(model.lb)) '\t']; +0265 end +0266 if isfield(model.annotation,'defaultUB') +0267 toPrint=[toPrint num2str(model.annotation.defaultUB) '\t']; +0268 else +0269 toPrint=[toPrint num2str(max(model.ub)) '\t']; +0270 end +0271 if isfield(model.annotation,'givenName') +0272 toPrint=[toPrint model.annotation.givenName '\t']; +0273 else +0274 toPrint=[toPrint '\t']; +0275 end +0276 if isfield(model.annotation,'familyName') +0277 toPrint=[toPrint model.annotation.familyName '\t']; +0278 else +0279 toPrint=[toPrint '\t']; +0280 end +0281 if isfield(model.annotation,'email') +0282 toPrint=[toPrint model.annotation.email '\t']; +0283 else +0284 toPrint=[toPrint '\t']; +0285 end +0286 if isfield(model.annotation,'organization') +0287 toPrint=[toPrint model.annotation.organization '\t']; +0288 else +0289 toPrint=[toPrint '\t']; +0290 end +0291 if isfield(model.annotation,'taxonomy') +0292 toPrint=[toPrint model.annotation.taxonomy '\t']; +0293 else +0294 toPrint=[toPrint '\t']; +0295 end +0296 if isfield(model.annotation,'note') +0297 toPrint=[toPrint model.annotation.note '\t']; +0298 else +0299 toPrint=[toPrint '\t']; +0300 end +0301 else +0302 toPrint=[toPrint num2str(min(model.lb)) '\t' num2str(max(model.ub)) '\t\t\t\t\t\t\n']; +0303 end +0304 fprintf(modelFile,toPrint); +0305 fclose(modelFile); +0306 end +0307 +0308 if isfield(model,'comps') +0309 %Open for printing the model sheet +0310 compsFile=fopen(fullfile(path,'excelComps.txt'),'wt'); +0311 +0312 %Print header +0313 fprintf(compsFile,'#\tABBREVIATION\tNAME\tINSIDE\tMIRIAM\n'); +0314 +0315 for i=1:numel(model.comps) +0316 toPrint=['\t' model.comps{i} '\t' model.compNames{i} '\t']; +0317 if isfield(model,'compOutside') +0318 toPrint=[toPrint model.compOutside{i} '\t']; +0319 else +0320 toPrint=[toPrint '\t']; +0321 end +0322 if isfield(model,'compMiriams') +0323 if ~isempty(model.compMiriams{i}) +0324 for j=1:numel(model.compMiriams{i}.name) +0325 toPrint=[toPrint strtrim(model.compMiriams{i}.name{j}) '/' strtrim(model.compMiriams{i}.value{j}) ';']; +0326 end +0327 toPrint(end)=[]; +0328 toPrint=[toPrint '\t']; +0329 else +0330 toPrint=[toPrint '\t']; +0331 end +0332 else +0333 toPrint=[toPrint '\t']; +0334 end +0335 toPrint=[toPrint '\n']; +0336 fprintf(compsFile,toPrint); +0337 end +0338 fclose(compsFile); +0339 end +0340 end

    Generated by m2html © 2005
    \ No newline at end of file diff --git a/doc/io/loadWorkbook.html b/doc/io/loadWorkbook.html index 7c06b146..ebca57da 100644 --- a/doc/io/loadWorkbook.html +++ b/doc/io/loadWorkbook.html @@ -46,7 +46,7 @@

    CROSS-REFERENCE INFORMATION ^
 <li><a href=addJavaPaths addJavaPaths
  • getFullPath getFullPath - Get absolute canonical path of a file or folder
  • This function is called by: +
  • exportToExcelFormat exportToExcelFormat
  • importExcelModel importExcelModel
  • diff --git a/doc/io/sortIdentifiers.html b/doc/io/sortIdentifiers.html new file mode 100644 index 00000000..33ae0b7d --- /dev/null +++ b/doc/io/sortIdentifiers.html @@ -0,0 +1,83 @@ + + + + Description of sortIdentifiers + + + + + + + + + +
    Home > io > sortIdentifiers.m
    + + + +

    sortIdentifiers +

    + +

    PURPOSE ^

    +
    exportModel
    + +

    SYNOPSIS ^

    +
    function newModel = sortIdentifiers(model)
    + +

    DESCRIPTION ^

    +
     exportModel
    +   Sort reactions, metabolites, genes and compartments alphabetically by
    +   their identifier.
    +
    +   Input:
    +   model       a model structure
    +
    +   Output:
    +   newModel    an updated model structure with alphabetically sorted
    +               identifiers
    +
    +   Usage: newModel=sortIdentifiers(model)
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + + + +

    SOURCE CODE ^

    +
    0001 function newModel = sortIdentifiers(model)
    +0002 % exportModel
    +0003 %   Sort reactions, metabolites, genes and compartments alphabetically by
    +0004 %   their identifier.
    +0005 %
    +0006 %   Input:
    +0007 %   model       a model structure
    +0008 %
    +0009 %   Output:
    +0010 %   newModel    an updated model structure with alphabetically sorted
    +0011 %               identifiers
    +0012 %
    +0013 %   Usage: newModel=sortIdentifiers(model)
    +0014 
    +0015 [~,I]=sort(model.rxns);
    +0016 newModel=permuteModel(model,I,'rxns');
    +0017 [~,I]=sort(newModel.mets);
    +0018 newModel=permuteModel(newModel,I,'mets');
    +0019 if isfield(newModel,'genes')
    +0020     [~,I]=sort(newModel.genes);
    +0021     newModel=permuteModel(newModel,I,'genes');
    +0022 end
    +0023 [~,I]=sort(newModel.comps);
    +0024 newModel=permuteModel(newModel,I,'comps');
    +0025 end
    +
    Generated by m2html © 2005
    + + \ No newline at end of file diff --git a/doc/io/writeSheet.html b/doc/io/writeSheet.html index 10b1aa8c..04270560 100644 --- a/doc/io/writeSheet.html +++ b/doc/io/writeSheet.html @@ -48,7 +48,7 @@

    CROSS-REFERENCE INFORMATION ^
 <li><a href=addJavaPaths addJavaPaths This function is called by: +
  • exportToExcelFormat exportToExcelFormat
  • SUBFUNCTIONS ^

    diff --git a/doc/io/writeYaml.html b/doc/io/writeYaml.html index c5a19c29..277e0b4b 100644 --- a/doc/io/writeYaml.html +++ b/doc/io/writeYaml.html @@ -45,7 +45,7 @@

    DESCRIPTION ^CROSS-REFERENCE INFORMATION ^

    This function calls: +
  • sortIdentifiers exportModel
  • This function is called by: @@ -77,298 +77,282 @@

    SOURCE CODE ^if nargin < 4 0020 sortIds = false; 0021 end -0022 -0023 if ~endsWith(name,{'.yml','.yaml'}) -0024 name = strcat(name,'.yml'); -0025 end -0026 -0027 %Check that model is in RAVEN format: -0028 if isfield(model,'rules') -0029 model = ravenCobraWrapper(model); -0030 end -0031 -0032 %Simplify Miriam fields: -0033 if isfield(model,'metMiriams') -0034 [model.newMetMiriams,model.newMetMiriamNames] = extractMiriam(model.metMiriams); -0035 model.newMetMiriams = regexprep(model.newMetMiriams,'^.+/',''); -0036 end -0037 if isfield(model,'rxnMiriams') -0038 [model.newRxnMiriams,model.newRxnMiriamNames] = extractMiriam(model.rxnMiriams); -0039 model.newRxnMiriams = regexprep(model.newRxnMiriams,'^.+/',''); +0022 if ~endsWith(name,{'.yml','.yaml'}) +0023 name = strcat(name,'.yml'); +0024 end +0025 +0026 %Check that model is in RAVEN format: +0027 if isfield(model,'rules') +0028 model = ravenCobraWrapper(model); +0029 end +0030 +0031 %Sort identifiers alphabetically +0032 if sortIds == true +0033 model = sortIdentifiers(model); +0034 end +0035 +0036 %Simplify Miriam fields: +0037 if isfield(model,'metMiriams') +0038 [model.newMetMiriams,model.newMetMiriamNames] = extractMiriam(model.metMiriams); +0039 model.newMetMiriams = regexprep(model.newMetMiriams,'^.+/',''); 0040 end -0041 if isfield(model,'geneMiriams') -0042 [model.newGeneMiriams,model.newGeneMiriamNames] = extractMiriam(model.geneMiriams); -0043 model.newGeneMiriams = regexprep(model.newGeneMiriams,'^.+/',''); +0041 if isfield(model,'rxnMiriams') +0042 [model.newRxnMiriams,model.newRxnMiriamNames] = extractMiriam(model.rxnMiriams); +0043 model.newRxnMiriams = regexprep(model.newRxnMiriams,'^.+/',''); 0044 end -0045 if isfield(model,'compMiriams') -0046 [model.newCompMiriams,model.newCompMiriamNames] = extractMiriam(model.compMiriams); -0047 model.newCompMiriams = regexprep(model.newCompMiriams,'^.+/',''); +0045 if isfield(model,'geneMiriams') +0046 [model.newGeneMiriams,model.newGeneMiriamNames] = extractMiriam(model.geneMiriams); +0047 model.newGeneMiriams = regexprep(model.newGeneMiriams,'^.+/',''); 0048 end -0049 -0050 %Open file: -0051 fid = fopen(name,'wt'); -0052 fprintf(fid,'---\n!!omap\n'); +0049 if isfield(model,'compMiriams') +0050 [model.newCompMiriams,model.newCompMiriamNames] = extractMiriam(model.compMiriams); +0051 model.newCompMiriams = regexprep(model.newCompMiriams,'^.+/',''); +0052 end 0053 -0054 %Insert file header (metadata) -0055 writeMetadata(model,fid); -0056 -0057 %Metabolites: -0058 fprintf(fid,'- metabolites:\n'); -0059 if sortIds==true -0060 [~,pos] = sort(model.mets); -0061 else -0062 pos = 1:numel(model.mets); -0063 end -0064 for i = 1:length(model.mets) -0065 fprintf(fid,' - !!omap\n'); -0066 writeField(model, fid, 'mets', 'txt', pos(i), ' - id', preserveQuotes) -0067 writeField(model, fid, 'metNames', 'txt', pos(i), ' - name', preserveQuotes) -0068 writeField(model, fid, 'metComps', 'txt', pos(i), ' - compartment', preserveQuotes) -0069 writeField(model, fid, 'metFormulas', 'txt', pos(i), ' - formula', preserveQuotes) -0070 writeField(model, fid, 'metCharges', 'num', pos(i), ' - charge', preserveQuotes) -0071 writeField(model, fid, 'inchis', 'txt', pos(i), ' - inchis', preserveQuotes) -0072 writeField(model, fid, 'metMiriams', 'txt', pos(i), ' - annotation', preserveQuotes) -0073 writeField(model, fid, 'metFrom', 'txt', pos(i), ' - metFrom', preserveQuotes) -0074 end -0075 -0076 %Reactions: -0077 fprintf(fid,'- reactions:\n'); -0078 if sortIds==true -0079 [~,pos] = sort(model.rxns); -0080 else -0081 pos = 1:numel(model.rxns); -0082 end -0083 for i = 1:length(model.rxns) -0084 fprintf(fid,' - !!omap\n'); -0085 writeField(model, fid, 'rxns', 'txt', pos(i), ' - id', preserveQuotes) -0086 writeField(model, fid, 'rxnNames', 'txt', pos(i), ' - name', preserveQuotes) -0087 writeField(model, fid, 'S', 'txt', pos(i), ' - metabolites', preserveQuotes) -0088 writeField(model, fid, 'lb', 'num', pos(i), ' - lower_bound', preserveQuotes) -0089 writeField(model, fid, 'ub', 'num', pos(i), ' - upper_bound', preserveQuotes) -0090 writeField(model, fid, 'grRules', 'txt', pos(i), ' - gene_reaction_rule', preserveQuotes) -0091 writeField(model, fid, 'rxnFrom', 'txt', pos(i), ' - rxnFrom', preserveQuotes) -0092 if model.c(i)~=0 -0093 writeField(model, fid, 'c', 'num', pos(i), ' - objective_coefficient', preserveQuotes) -0094 end -0095 writeField(model, fid, 'eccodes', 'txt', pos(i), ' - eccodes', preserveQuotes) -0096 writeField(model, fid, 'rxnReferences', 'txt', pos(i), ' - references', preserveQuotes) -0097 writeField(model, fid, 'subSystems', 'txt', pos(i), ' - subsystem', preserveQuotes) -0098 writeField(model, fid, 'rxnMiriams', 'txt', pos(i), ' - annotation', preserveQuotes) -0099 writeField(model, fid, 'rxnConfidenceScores', 'num', pos(i), ' - confidence_score', preserveQuotes) -0100 end -0101 -0102 %Genes: -0103 fprintf(fid,'- genes:\n'); -0104 if sortIds==true -0105 [~,pos] = sort(model.genes); -0106 else -0107 pos = 1:numel(model.genes); -0108 end -0109 for i = 1:length(model.genes) -0110 fprintf(fid,' - !!omap\n'); -0111 writeField(model, fid, 'genes', 'txt', pos(i), ' - id', preserveQuotes) -0112 writeField(model, fid, 'geneShortNames', 'txt', pos(i), ' - name', preserveQuotes) -0113 writeField(model, fid, 'geneMiriams', 'txt', pos(i), ' - annotation', preserveQuotes) -0114 end -0115 -0116 %Compartments: -0117 fprintf(fid,'- compartments: !!omap\n'); -0118 if sortIds==true -0119 [~,pos] = sort(model.comps); -0120 else -0121 pos = 1:numel(model.comps); -0122 end -0123 for i = 1:length(model.comps) -0124 writeField(model, fid, 'compNames', 'txt', pos(i), ['- ' model.comps{pos(i)}], preserveQuotes) -0125 writeField(model, fid, 'compMiriams', 'txt', pos(i), '- annotation', preserveQuotes) -0126 end -0127 -0128 %Close file: -0129 fclose(fid); -0130 -0131 end -0132 -0133 function writeField(model,fid,fieldName,type,pos,name,preserveQuotes) -0134 %Writes a new line in the yaml file if the field exists and the field is -0135 %not empty at the correspoinding position. It's recursive for some fields -0136 %(metMiriams, rxnMiriams, and S) -0137 -0138 if isfield(model,fieldName) -0139 if strcmp(fieldName,'metComps') -0140 %metComps: write full name -0141 fieldName = 'comps'; -0142 pos = model.metComps(pos); -0143 end -0144 -0145 field = eval(['model.' fieldName]); -0146 -0147 if strcmp(fieldName,'metMiriams') -0148 if ~isempty(model.metMiriams{pos}) -0149 fprintf(fid,[' ' name ': !!omap\n']); -0150 for i=1:size(model.newMetMiriams,2) -0151 %'i' represents the different miriam names, e.g. -0152 %kegg.compound or chebi -0153 if ~isempty(model.newMetMiriams{pos,i}) -0154 %As during the following writeField call the value of -0155 %'i' would be lost, it is temporarily concatenated to -0156 %'name' parameter, which will be edited later -0157 writeField(model, fid, 'newMetMiriams', 'txt', pos, [' - ' model.newMetMiriamNames{i} '_' num2str(i)], preserveQuotes) -0158 end -0159 end -0160 end -0161 -0162 elseif strcmp(fieldName,'rxnMiriams') -0163 if ~isempty(model.rxnMiriams{pos}) -0164 fprintf(fid,[' ' name ': !!omap\n']); -0165 for i=1:size(model.newRxnMiriams,2) -0166 if ~isempty(model.newRxnMiriams{pos,i}) -0167 writeField(model, fid, 'newRxnMiriams', 'txt', pos, [' - ' model.newRxnMiriamNames{i} '_' num2str(i)], preserveQuotes) -0168 end -0169 end -0170 end -0171 -0172 elseif strcmp(fieldName,'geneMiriams') -0173 if ~isempty(model.geneMiriams{pos}) -0174 fprintf(fid,[' ' name ': !!omap\n']); -0175 for i=1:size(model.newGeneMiriams,2) -0176 if ~isempty(model.newGeneMiriams{pos,i}) -0177 writeField(model, fid, 'newGeneMiriams', 'txt', pos, [' - ' model.newGeneMiriamNames{i} '_' num2str(i)], preserveQuotes) -0178 end -0179 end -0180 end -0181 -0182 elseif strcmp(fieldName,'compMiriams') -0183 if ~isempty(model.compMiriams{pos}) -0184 fprintf(fid,[' ' name ': !!omap\n']); -0185 for i=1:size(model.newCompMiriams,2) -0186 if ~isempty(model.newCompMiriams{pos,i}) -0187 writeField(model, fid, 'newCompMiriams', 'txt', pos, [' - ' model.newCompMiriamNames{i} '_' num2str(i)], preserveQuotes) -0188 end -0189 end -0190 end -0191 -0192 elseif strcmp(fieldName,'S') -0193 %S: create header & write each metabolite in a new line -0194 fprintf(fid,[' ' name ': !!omap\n']); -0195 if sum(field(:,pos) ~= 0) > 0 -0196 model.mets = model.mets(field(:,pos) ~= 0); -0197 model.coeffs = field(field(:,pos) ~= 0,pos); -0198 %Sort metabolites: -0199 [model.mets,order] = sort(model.mets); -0200 model.coeffs = model.coeffs(order); -0201 for i = 1:length(model.mets) -0202 writeField(model, fid, 'coeffs', 'num', i, [' - ' model.mets{i}], preserveQuotes) -0203 end -0204 end -0205 -0206 elseif sum(strcmp({'subSystems','newMetMiriams','newRxnMiriams','newGeneMiriams','newCompMiriams','eccodes'},fieldName)) > 0 -0207 %eccodes/rxnNotes: if 1 write in 1 line, if more create header and list -0208 if strcmp(fieldName,'subSystems') -0209 list = field{pos}; %subSystems already comes in a cell array -0210 elseif strcmp(fieldName,'newMetMiriams') -0211 index = str2double(regexprep(name,'^.+_','')); -0212 name = regexprep(name,'_\d+$',''); -0213 list = strsplit(model.newMetMiriams{pos,index},'; '); -0214 elseif strcmp(fieldName,'newRxnMiriams') -0215 index = str2double(regexprep(name,'^.+_','')); -0216 name = regexprep(name,'_\d+$',''); -0217 list = strsplit(model.newRxnMiriams{pos,index},'; '); -0218 elseif strcmp(fieldName,'newGeneMiriams') -0219 index = str2double(regexprep(name,'^.+_','')); -0220 name = regexprep(name,'_\d+$',''); -0221 list = strsplit(model.newGeneMiriams{pos,index},'; '); -0222 elseif strcmp(fieldName,'newCompMiriams') -0223 index = str2double(regexprep(name,'^.+_','')); -0224 name = regexprep(name,'_\d+$',''); -0225 list = strsplit(model.newCompMiriams{pos,index},'; '); -0226 else -0227 list = strrep(field{pos},' ',''); %Exception for eccodes -0228 list = strsplit(list,';'); -0229 end -0230 -0231 if length(list) == 1 && ~strcmp(list{1},'') && ~strcmp(fieldName,'subSystems') -0232 if preserveQuotes -0233 list = strcat('"',list,'"'); -0234 end -0235 fprintf(fid,[' ' name ': ' list{1} '\n']); -0236 elseif length(list) > 1 || strcmp(fieldName,'subSystems') -0237 if preserveQuotes -0238 list = strcat('"',list,'"'); -0239 end -0240 fprintf(fid,[' ' name ':\n']); -0241 for i = 1:length(list) -0242 fprintf(fid,[regexprep(name,'(^\s*).*','$1') ' - ' list{i} '\n']); -0243 end -0244 end -0245 -0246 elseif sum(pos) > 0 -0247 %All other fields: -0248 if strcmp(type,'txt') -0249 value = field{pos}; -0250 if preserveQuotes && ~isempty(value) -0251 value = strcat('"',value,'"'); -0252 end -0253 elseif strcmp(type,'num') -0254 if isnan(field(pos)) -0255 value = []; -0256 else -0257 value = num2str(field(pos),12); -0258 end -0259 end -0260 if ~isempty(value) -0261 fprintf(fid,[' ' name ': ' value '\n']); -0262 end -0263 end -0264 end -0265 -0266 -0267 end -0268 -0269 function writeMetadata(model,fid) -0270 % Writes model metadata to the yaml file. This information will eventually -0271 % be extracted entirely from the model, but for now, many of the entries -0272 % are hard-coded defaults for HumanGEM. -0273 -0274 fprintf(fid, '- metaData:\n'); -0275 fprintf(fid, [' id: "', model.id, '"\n']); -0276 fprintf(fid, [' name: "', model.name, '"\n']); -0277 if isfield(model,'version') -0278 fprintf(fid, [' version: "', model.version, '"\n']); -0279 end -0280 fprintf(fid, [' date: "', datestr(now,29), '"\n']); % 29=YYYY-MM-DD -0281 if isfield(model,'annotation') -0282 if isfield(model.annotation,'defaultLB') -0283 fprintf(fid, [' defaultLB: "', num2str(model.annotation.defaultLB), '"\n']); -0284 end -0285 if isfield(model.annotation,'defaultUB') -0286 fprintf(fid, [' defaultUB: "', num2str(model.annotation.defaultUB), '"\n']); -0287 end -0288 if isfield(model.annotation,'givenName') -0289 fprintf(fid, [' givenName: "', model.annotation.givenName, '"\n']); -0290 end -0291 if isfield(model.annotation,'familyName') -0292 fprintf(fid, [' familyName: "', model.annotation.familyName, '"\n']); -0293 end -0294 if isfield(model.annotation,'authors') -0295 fprintf(fid, [' authors: "', model.annotation.authors, '"\n']); -0296 end -0297 if isfield(model.annotation,'email') -0298 fprintf(fid, [' email: "', model.annotation.email, '"\n']); -0299 end -0300 if isfield(model.annotation,'organization') -0301 fprintf(fid, [' organization: "', model.annotation.organization, '"\n']); -0302 end -0303 if isfield(model.annotation,'taxonomy') -0304 fprintf(fid, [' taxonomy: "', model.annotation.taxonomy, '"\n']); -0305 end -0306 if isfield(model.annotation,'note') -0307 fprintf(fid, [' note: "', model.annotation.note, '"\n']); -0308 end -0309 if isfield(model.annotation,'sourceUrl') -0310 fprintf(fid, [' sourceUrl: "', model.annotation.sourceUrl, '"\n']); -0311 end -0312 end -0313 end

    +0054 %Open file: +0055 fid = fopen(name,'wt'); +0056 fprintf(fid,'---\n!!omap\n'); +0057 +0058 %Insert file header (metadata) +0059 writeMetadata(model,fid); +0060 +0061 %Metabolites: +0062 fprintf(fid,'- metabolites:\n'); +0063 for i = 1:length(model.mets) +0064 fprintf(fid,' - !!omap\n'); +0065 writeField(model, fid, 'mets', 'txt', pos(i), ' - id', preserveQuotes) +0066 writeField(model, fid, 'metNames', 'txt', pos(i), ' - name', preserveQuotes) +0067 writeField(model, fid, 'metComps', 'txt', pos(i), ' - compartment', preserveQuotes) +0068 writeField(model, fid, 'metFormulas', 'txt', pos(i), ' - formula', preserveQuotes) +0069 writeField(model, fid, 'metCharges', 'num', pos(i), ' - charge', preserveQuotes) +0070 writeField(model, fid, 'inchis', 'txt', pos(i), ' - inchis', preserveQuotes) +0071 writeField(model, fid, 'metMiriams', 'txt', pos(i), ' - annotation', preserveQuotes) +0072 writeField(model, fid, 'metFrom', 'txt', pos(i), ' - metFrom', preserveQuotes) +0073 end +0074 +0075 %Reactions: +0076 fprintf(fid,'- reactions:\n'); +0077 for i = 1:length(model.rxns) +0078 fprintf(fid,' - !!omap\n'); +0079 writeField(model, fid, 'rxns', 'txt', pos(i), ' - id', preserveQuotes) +0080 writeField(model, fid, 'rxnNames', 'txt', pos(i), ' - name', preserveQuotes) +0081 writeField(model, fid, 'S', 'txt', pos(i), ' - metabolites', preserveQuotes) +0082 writeField(model, fid, 'lb', 'num', pos(i), ' - lower_bound', preserveQuotes) +0083 writeField(model, fid, 'ub', 'num', pos(i), ' - upper_bound', preserveQuotes) +0084 writeField(model, fid, 'grRules', 'txt', pos(i), ' - gene_reaction_rule', preserveQuotes) +0085 writeField(model, fid, 'rxnFrom', 'txt', pos(i), ' - rxnFrom', preserveQuotes) +0086 if model.c(i)~=0 +0087 writeField(model, fid, 'c', 'num', pos(i), ' - objective_coefficient', preserveQuotes) +0088 end +0089 writeField(model, fid, 'eccodes', 'txt', pos(i), ' - eccodes', preserveQuotes) +0090 writeField(model, fid, 'rxnReferences', 'txt', pos(i), ' - references', preserveQuotes) +0091 writeField(model, fid, 'subSystems', 'txt', pos(i), ' - subsystem', preserveQuotes) +0092 writeField(model, fid, 'rxnMiriams', 'txt', pos(i), ' - annotation', preserveQuotes) +0093 writeField(model, fid, 'rxnConfidenceScores', 'num', pos(i), ' - confidence_score', preserveQuotes) +0094 end +0095 +0096 %Genes: +0097 fprintf(fid,'- genes:\n'); +0098 for i = 1:length(model.genes) +0099 fprintf(fid,' - !!omap\n'); +0100 writeField(model, fid, 'genes', 'txt', pos(i), ' - id', preserveQuotes) +0101 writeField(model, fid, 'geneShortNames', 'txt', pos(i), ' - name', preserveQuotes) +0102 writeField(model, fid, 'geneMiriams', 'txt', pos(i), ' - annotation', preserveQuotes) +0103 end +0104 +0105 %Compartments: +0106 fprintf(fid,'- compartments: !!omap\n'); +0107 for i = 1:length(model.comps) +0108 writeField(model, fid, 'compNames', 'txt', pos(i), ['- ' model.comps{pos(i)}], preserveQuotes) +0109 writeField(model, fid, 'compMiriams', 'txt', pos(i), '- annotation', preserveQuotes) +0110 end +0111 +0112 %Close file: +0113 fclose(fid); +0114 +0115 end +0116 +0117 function writeField(model,fid,fieldName,type,pos,name,preserveQuotes) +0118 %Writes a new line in the yaml file if the field exists and the field is +0119 %not empty at the correspoinding position. It's recursive for some fields +0120 %(metMiriams, rxnMiriams, and S) +0121 +0122 if isfield(model,fieldName) +0123 if strcmp(fieldName,'metComps') +0124 %metComps: write full name +0125 fieldName = 'comps'; +0126 pos = model.metComps(pos); +0127 end +0128 +0129 field = eval(['model.' fieldName]); +0130 +0131 if strcmp(fieldName,'metMiriams') +0132 if ~isempty(model.metMiriams{pos}) +0133 fprintf(fid,[' ' name ': !!omap\n']); +0134 for i=1:size(model.newMetMiriams,2) +0135 %'i' represents the different miriam names, e.g. +0136 %kegg.compound or chebi +0137 if ~isempty(model.newMetMiriams{pos,i}) +0138 %As during the following writeField call the value of +0139 %'i' would be lost, it is temporarily concatenated to +0140 %'name' parameter, which will be edited later +0141 writeField(model, fid, 'newMetMiriams', 'txt', pos, [' - ' model.newMetMiriamNames{i} '_' num2str(i)], preserveQuotes) +0142 end +0143 end +0144 end +0145 +0146 elseif strcmp(fieldName,'rxnMiriams') +0147 if ~isempty(model.rxnMiriams{pos}) +0148 fprintf(fid,[' ' name ': !!omap\n']); +0149 for i=1:size(model.newRxnMiriams,2) +0150 if ~isempty(model.newRxnMiriams{pos,i}) +0151 writeField(model, fid, 'newRxnMiriams', 'txt', pos, [' - ' model.newRxnMiriamNames{i} '_' num2str(i)], preserveQuotes) +0152 end +0153 end +0154 end +0155 +0156 elseif strcmp(fieldName,'geneMiriams') +0157 if ~isempty(model.geneMiriams{pos}) +0158 fprintf(fid,[' ' name ': !!omap\n']); +0159 for i=1:size(model.newGeneMiriams,2) +0160 if ~isempty(model.newGeneMiriams{pos,i}) +0161 writeField(model, fid, 'newGeneMiriams', 'txt', pos, [' - ' model.newGeneMiriamNames{i} '_' num2str(i)], preserveQuotes) +0162 end +0163 end +0164 end +0165 +0166 elseif strcmp(fieldName,'compMiriams') +0167 if ~isempty(model.compMiriams{pos}) +0168 fprintf(fid,[' ' name ': !!omap\n']); +0169 for i=1:size(model.newCompMiriams,2) +0170 if ~isempty(model.newCompMiriams{pos,i}) +0171 writeField(model, fid, 'newCompMiriams', 'txt', pos, [' - ' model.newCompMiriamNames{i} '_' num2str(i)], preserveQuotes) +0172 end +0173 end +0174 end +0175 +0176 elseif strcmp(fieldName,'S') +0177 %S: create header & write each metabolite in a new line +0178 fprintf(fid,[' ' name ': !!omap\n']); +0179 if sum(field(:,pos) ~= 0) > 0 +0180 model.mets = model.mets(field(:,pos) ~= 0); +0181 model.coeffs = field(field(:,pos) ~= 0,pos); +0182 %Sort metabolites: +0183 [model.mets,order] = sort(model.mets); +0184 model.coeffs = model.coeffs(order); +0185 for i = 1:length(model.mets) +0186 writeField(model, fid, 'coeffs', 'num', i, [' - ' model.mets{i}], preserveQuotes) +0187 end +0188 end +0189 +0190 elseif sum(strcmp({'subSystems','newMetMiriams','newRxnMiriams','newGeneMiriams','newCompMiriams','eccodes'},fieldName)) > 0 +0191 %eccodes/rxnNotes: if 1 write in 1 line, if more create header and list +0192 if strcmp(fieldName,'subSystems') +0193 list = field{pos}; %subSystems already comes in a cell array +0194 elseif strcmp(fieldName,'newMetMiriams') +0195 index = str2double(regexprep(name,'^.+_','')); +0196 name = regexprep(name,'_\d+$',''); +0197 list = strsplit(model.newMetMiriams{pos,index},'; '); +0198 elseif strcmp(fieldName,'newRxnMiriams') +0199 index = str2double(regexprep(name,'^.+_','')); +0200 name = regexprep(name,'_\d+$',''); +0201 list = strsplit(model.newRxnMiriams{pos,index},'; '); +0202 elseif strcmp(fieldName,'newGeneMiriams') +0203 index = str2double(regexprep(name,'^.+_','')); +0204 name = regexprep(name,'_\d+$',''); +0205 list = strsplit(model.newGeneMiriams{pos,index},'; '); +0206 elseif strcmp(fieldName,'newCompMiriams') +0207 index = str2double(regexprep(name,'^.+_','')); +0208 name = regexprep(name,'_\d+$',''); +0209 list = strsplit(model.newCompMiriams{pos,index},'; '); +0210 else +0211 list = strrep(field{pos},' ',''); %Exception for eccodes +0212 list = strsplit(list,';'); +0213 end +0214 +0215 if length(list) == 1 && ~strcmp(list{1},'') && ~strcmp(fieldName,'subSystems') +0216 if preserveQuotes +0217 list = strcat('"',list,'"'); +0218 end +0219 fprintf(fid,[' ' name ': ' list{1} '\n']); +0220 elseif length(list) > 1 || strcmp(fieldName,'subSystems') +0221 if preserveQuotes +0222 list = strcat('"',list,'"'); +0223 end +0224 fprintf(fid,[' ' name ':\n']); +0225 for i = 1:length(list) +0226 fprintf(fid,[regexprep(name,'(^\s*).*','$1') ' - ' list{i} '\n']); +0227 end +0228 end +0229 +0230 elseif sum(pos) > 0 +0231 %All other fields: +0232 if strcmp(type,'txt') +0233 value = field{pos}; +0234 if preserveQuotes && ~isempty(value) +0235 value = strcat('"',value,'"'); +0236 end +0237 elseif strcmp(type,'num') +0238 if isnan(field(pos)) +0239 value = []; +0240 else +0241 value = num2str(field(pos),12); +0242 end +0243 end +0244 if ~isempty(value) +0245 fprintf(fid,[' ' name ': ' value '\n']); +0246 end +0247 end +0248 end +0249 +0250 +0251 end +0252 +0253 function writeMetadata(model,fid) +0254 % Writes model metadata to the yaml file. This information will eventually +0255 % be extracted entirely from the model, but for now, many of the entries +0256 % are hard-coded defaults for HumanGEM. +0257 +0258 fprintf(fid, '- metaData:\n'); +0259 fprintf(fid, [' id: "', model.id, '"\n']); +0260 fprintf(fid, [' name: "', model.name, '"\n']); +0261 if isfield(model,'version') +0262 fprintf(fid, [' version: "', model.version, '"\n']); +0263 end +0264 fprintf(fid, [' date: "', datestr(now,29), '"\n']); % 29=YYYY-MM-DD +0265 if isfield(model,'annotation') +0266 if isfield(model.annotation,'defaultLB') +0267 fprintf(fid, [' defaultLB: "', num2str(model.annotation.defaultLB), '"\n']); +0268 end +0269 if isfield(model.annotation,'defaultUB') +0270 fprintf(fid, [' defaultUB: "', num2str(model.annotation.defaultUB), '"\n']); +0271 end +0272 if isfield(model.annotation,'givenName') +0273 fprintf(fid, [' givenName: "', model.annotation.givenName, '"\n']); +0274 end +0275 if isfield(model.annotation,'familyName') +0276 fprintf(fid, [' familyName: "', model.annotation.familyName, '"\n']); +0277 end +0278 if isfield(model.annotation,'authors') +0279 fprintf(fid, [' authors: "', model.annotation.authors, '"\n']); +0280 end +0281 if isfield(model.annotation,'email') +0282 fprintf(fid, [' email: "', model.annotation.email, '"\n']); +0283 end +0284 if isfield(model.annotation,'organization') +0285 fprintf(fid, [' organization: "', model.annotation.organization, '"\n']); +0286 end +0287 if isfield(model.annotation,'taxonomy') +0288 fprintf(fid, [' taxonomy: "', model.annotation.taxonomy, '"\n']); +0289 end +0290 if isfield(model.annotation,'note') +0291 fprintf(fid, [' note: "', model.annotation.note, '"\n']); +0292 end +0293 if isfield(model.annotation,'sourceUrl') +0294 fprintf(fid, [' sourceUrl: "', model.annotation.sourceUrl, '"\n']); +0295 end +0296 end +0297 end
    Generated by m2html © 2005
    \ No newline at end of file diff --git a/doc/testing/unit_tests/sortIdentifiers_and_permuteModelTests.html b/doc/testing/unit_tests/sortIdentifiers_and_permuteModelTests.html new file mode 100644 index 00000000..c719b047 --- /dev/null +++ b/doc/testing/unit_tests/sortIdentifiers_and_permuteModelTests.html @@ -0,0 +1,103 @@ + + + + Description of sortIdentifiers_and_permuteModelTests + + + + + + + + + +
    Home > testing > unit_tests > sortIdentifiers_and_permuteModelTests.m
    + + + +

    sortIdentifiers_and_permuteModelTests +

    + +

    PURPOSE ^

    +
    run this test case with the command
    + +

    SYNOPSIS ^

    +
    function tests = sortIdentifiers_and_permuteModelTests
    + +

    DESCRIPTION ^

    +
    run this test case with the command
    +results = runtests('sortIdentifiers_and_permuteModelTests.m')
    + + +

    CROSS-REFERENCE INFORMATION ^

    +This function calls: + +This function is called by: + + + +

    SUBFUNCTIONS ^

    + + +

    SOURCE CODE ^

    +
    0001 %run this test case with the command
    +0002 %results = runtests('sortIdentifiers_and_permuteModelTests.m')
    +0003 function tests = sortIdentifiers_and_permuteModelTests
    +0004 tests = functiontests(localfunctions);
    +0005 end
    +0006 
    +0007 function sortRandomizedModelTest(testCase)
    +0008 
    +0009 %Load the expected (i.e. sorted) model
    +0010 sourceDir = fileparts(which(mfilename));
    +0011 load([sourceDir,'/test_data/ecoli_textbook.mat'], expModel);
    +0012 
    +0013 %Create the actual model that will be permuted and sorted
    +0014 actModel = expModel;
    +0015 
    +0016 %Randomly permutate model, do not use RAVEN functions
    +0017 rndIdx = randperm(numel(actModel.rxns));
    +0018 fieldsToChange = {'rxns','lb','ub','rev','c','rxnNames','grRules','eccodes'};
    +0019 for i=1:numel(fieldsToChange)
    +0020     actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx);
    +0021 end
    +0022 actModel.S          = actModel.S(:,rndIdx);
    +0023 actModel.rxnGeneMat = actModel.rxnGeneMat(rndIdx,:);
    +0024 
    +0025 rndIdx = randperm(numel(actModel.mets));
    +0026 fieldsToChange = {'mets','metNames','metComps','metFormulas'};
    +0027 for i=1:numel(fieldsToChange)
    +0028     actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx);
    +0029 end
    +0030 actModel.S     = actModel.S(rndIdx,:);
    +0031 
    +0032 rndIdx = randperm(numel(actModel.genes));
    +0033 fieldsToChange = {'genes','geneShortNames'};
    +0034 for i=1:numel(fieldsToChange)
    +0035     actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx);
    +0036 end
    +0037 actModel.rxnGeneMat = actModel.rxnGeneMat(:,rndIdx);
    +0038 
    +0039 rndIdx = randperm(numel(actModel.comps));
    +0040 fieldsToChange = {'comps','compNames'};
    +0041 for i=1:numel(fieldsToChange)
    +0042     actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx);
    +0043 end
    +0044 [~,J]=sort(rndIdx);
    +0045 [toreplace, bywhat] = ismember(actModel.metComps,1:length(J));
    +0046 actModel.metComps(toreplace) = J(bywhat(toreplace));
    +0047 
    +0048 %Sort randomly permuted model
    +0049 actModel = sortIdentifiers(actModel);
    +0050 
    +0051 %Check that the actual model is the same as the expected model
    +0052 verifyEqual(testCase,actModel,expModel)
    +0053 end
    +
    Generated by m2html © 2005
    + + \ No newline at end of file diff --git a/io/exportForGit.m b/io/exportForGit.m index e7da5112..1f80068b 100755 --- a/io/exportForGit.m +++ b/io/exportForGit.m @@ -46,6 +46,9 @@ prefix='model'; end +%Sort reactions, metabolites and genes alphabetically +model=sortIdentifiers(model); + %Get versions or commits of toolboxes: RAVENver = getToolboxVersion('RAVEN','ravenCobraWrapper.m',masterFlag); COBRAver = getToolboxVersion('COBRA','initCobraToolbox.m',masterFlag); diff --git a/io/exportModel.m b/io/exportModel.m index b51c0b12..be5b64ea 100755 --- a/io/exportModel.m +++ b/io/exportModel.m @@ -1,4 +1,4 @@ -function exportModel(model,fileName,exportGeneComplexes,supressWarnings) +function exportModel(model,fileName,exportGeneComplexes,supressWarnings,sortIds) % exportModel % Exports a constraint-based model to an SBML file (L3V1 FBCv2) % @@ -10,15 +10,23 @@ function exportModel(model,fileName,exportGeneComplexes,supressWarnings) % (opt, default false) % supressWarnings true if warnings should be supressed (opt, default % false) +% sortIds logical whether metabolites, reactions and genes +% should be sorted alphabetically by their +% identifiers (opt, default false) % -% -% Usage: exportModel(model,fileName,exportGeneComplexes,supressWarnings) +% Usage: exportModel(model,fileName,exportGeneComplexes,supressWarnings,sortIds) if nargin<3 exportGeneComplexes=false; end if nargin<4 supressWarnings=false; end +if nargin<5 + sortIds=false; +end +if sortIds==true + model=sortIdentifiers(model); +end %If no subSystems are defined, then no need to use groups package if isfield(model,'subSystems') diff --git a/io/exportToExcelFormat.m b/io/exportToExcelFormat.m index d15a006b..75a6cd34 100755 --- a/io/exportToExcelFormat.m +++ b/io/exportToExcelFormat.m @@ -1,4 +1,4 @@ -function exportToExcelFormat(model,filename) +function exportToExcelFormat(model,filename,sortIds) % exportToExcelFormat % Exports a model structure to the Microsoft Excel model format % @@ -8,6 +8,9 @@ function exportToExcelFormat(model,filename) % be only a path, in which case the model is exported to a set % of tab-delimited text files instead. See exportToTabDelimited % for details regarding that functionality +% sortIds logical whether metabolites, reactions and genes should be +% sorted alphabetically by their identifiers (opt, default +% false) % % The resulting Excel file can be used with importExcelModel/SBMLFromExcel % for modelling or to generate a SBML file. @@ -15,7 +18,13 @@ function exportToExcelFormat(model,filename) % NOTE: No checks are made regarding the correctness of the model. Use % checkModelStruct to identify problems in the model structure % -% Usage: exportToExcelFormat(model,filename) +% Usage: exportToExcelFormat(model,filename,sortIds) +if nargin<3 + sortIds=false; +end +if sortIds==true + model=sortIdentifiers(model); +end [~, A, B]=fileparts(filename); diff --git a/io/exportToTabDelimited.m b/io/exportToTabDelimited.m index b015bad1..137f7601 100755 --- a/io/exportToTabDelimited.m +++ b/io/exportToTabDelimited.m @@ -1,4 +1,4 @@ -function exportToTabDelimited(model,path) +function exportToTabDelimited(model,path,sortIds) % exportToTabDelimited % Exports a model structure to a set of tab-delimited text files % @@ -6,6 +6,8 @@ function exportToTabDelimited(model,path) % path the path to export to. The resulting text files will be saved % under the names excelRxns.txt, excelMets.txt, excelGenes.txt, % excelModel.txt, and excelComps.txt +% sortIds logical whether metabolites, reactions and genes should be +% sorted alphabetically by their identifiers (opt, default false) % % NOTE: This functionality was previously a part of exportToExcelFormat. % The naming of the resulting text files is to preserve backward @@ -14,11 +16,17 @@ function exportToTabDelimited(model,path) % NOTE: No checks are made regarding the correctness of the model. Use % checkModelStruct to identify problems in the model structure % -% Usage: exportToTabDelimited(model,path) +% Usage: exportToTabDelimited(model,path,sortIds) if nargin<2 path='./'; end +if nargin<3 + sortIds=false; +end +if sortIds==true + model=sortIdentifiers(model); +end %If the folder doesn't exist then create it if ~exist(path,'dir') diff --git a/io/sortIdentifiers.m b/io/sortIdentifiers.m new file mode 100644 index 00000000..2974a9eb --- /dev/null +++ b/io/sortIdentifiers.m @@ -0,0 +1,25 @@ +function newModel = sortIdentifiers(model) +% exportModel +% Sort reactions, metabolites, genes and compartments alphabetically by +% their identifier. +% +% Input: +% model a model structure +% +% Output: +% newModel an updated model structure with alphabetically sorted +% identifiers +% +% Usage: newModel=sortIdentifiers(model) + +[~,I]=sort(model.rxns); +newModel=permuteModel(model,I,'rxns'); +[~,I]=sort(newModel.mets); +newModel=permuteModel(newModel,I,'mets'); +if isfield(newModel,'genes') + [~,I]=sort(newModel.genes); + newModel=permuteModel(newModel,I,'genes'); +end +[~,I]=sort(newModel.comps); +newModel=permuteModel(newModel,I,'comps'); +end \ No newline at end of file diff --git a/io/writeYaml.m b/io/writeYaml.m index 1a29ccdd..0f5199d6 100755 --- a/io/writeYaml.m +++ b/io/writeYaml.m @@ -19,7 +19,6 @@ function writeYaml(model,name,preserveQuotes,sortIds) if nargin < 4 sortIds = false; end - if ~endsWith(name,{'.yml','.yaml'}) name = strcat(name,'.yml'); end @@ -29,6 +28,11 @@ function writeYaml(model,name,preserveQuotes,sortIds) model = ravenCobraWrapper(model); end +%Sort identifiers alphabetically +if sortIds == true + model = sortIdentifiers(model); +end + %Simplify Miriam fields: if isfield(model,'metMiriams') [model.newMetMiriams,model.newMetMiriamNames] = extractMiriam(model.metMiriams); @@ -56,11 +60,6 @@ function writeYaml(model,name,preserveQuotes,sortIds) %Metabolites: fprintf(fid,'- metabolites:\n'); -if sortIds==true - [~,pos] = sort(model.mets); -else - pos = 1:numel(model.mets); -end for i = 1:length(model.mets) fprintf(fid,' - !!omap\n'); writeField(model, fid, 'mets', 'txt', pos(i), ' - id', preserveQuotes) @@ -75,11 +74,6 @@ function writeYaml(model,name,preserveQuotes,sortIds) %Reactions: fprintf(fid,'- reactions:\n'); -if sortIds==true - [~,pos] = sort(model.rxns); -else - pos = 1:numel(model.rxns); -end for i = 1:length(model.rxns) fprintf(fid,' - !!omap\n'); writeField(model, fid, 'rxns', 'txt', pos(i), ' - id', preserveQuotes) @@ -101,11 +95,6 @@ function writeYaml(model,name,preserveQuotes,sortIds) %Genes: fprintf(fid,'- genes:\n'); -if sortIds==true - [~,pos] = sort(model.genes); -else - pos = 1:numel(model.genes); -end for i = 1:length(model.genes) fprintf(fid,' - !!omap\n'); writeField(model, fid, 'genes', 'txt', pos(i), ' - id', preserveQuotes) @@ -115,11 +104,6 @@ function writeYaml(model,name,preserveQuotes,sortIds) %Compartments: fprintf(fid,'- compartments: !!omap\n'); -if sortIds==true - [~,pos] = sort(model.comps); -else - pos = 1:numel(model.comps); -end for i = 1:length(model.comps) writeField(model, fid, 'compNames', 'txt', pos(i), ['- ' model.comps{pos(i)}], preserveQuotes) writeField(model, fid, 'compMiriams', 'txt', pos(i), '- annotation', preserveQuotes) diff --git a/testing/unit_tests/sortIdentifiers_and_permuteModelTests.m b/testing/unit_tests/sortIdentifiers_and_permuteModelTests.m new file mode 100644 index 00000000..26cb61a4 --- /dev/null +++ b/testing/unit_tests/sortIdentifiers_and_permuteModelTests.m @@ -0,0 +1,54 @@ +%run this test case with the command +%results = runtests('sortIdentifiers_and_permuteModelTests.m') +function tests = sortIdentifiers_and_permuteModelTests +tests = functiontests(localfunctions); +end + +function sortRandomizedModelTest(testCase) + +%Load the expected (i.e. sorted) model +sourceDir = fileparts(which(mfilename)); +load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model'); +expModel = model; + +%Create the actual model that will be permuted and sorted +actModel = expModel; + +%Randomly permutate model, do not use RAVEN functions +rndIdx = randperm(numel(actModel.rxns)); +fieldsToChange = {'rxns','lb','ub','rev','c','rxnNames','grRules','eccodes'}; +for i=1:numel(fieldsToChange) + actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx); +end +actModel.S = actModel.S(:,rndIdx); +actModel.rxnGeneMat = actModel.rxnGeneMat(rndIdx,:); + +rndIdx = randperm(numel(actModel.mets)); +fieldsToChange = {'mets','metNames','metComps','metFormulas'}; +for i=1:numel(fieldsToChange) + actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx); +end +actModel.S = actModel.S(rndIdx,:); + +rndIdx = randperm(numel(actModel.genes)); +fieldsToChange = {'genes','geneShortNames'}; +for i=1:numel(fieldsToChange) + actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx); +end +actModel.rxnGeneMat = actModel.rxnGeneMat(:,rndIdx); + +rndIdx = randperm(numel(actModel.comps)); +fieldsToChange = {'comps','compNames'}; +for i=1:numel(fieldsToChange) + actModel.(fieldsToChange{i}) = actModel.(fieldsToChange{i})(rndIdx); +end +[~,J]=sort(rndIdx); +[toreplace, bywhat] = ismember(actModel.metComps,1:length(J)); +actModel.metComps(toreplace) = J(bywhat(toreplace)); + +%Sort randomly permutated model +actModel = sortIdentifiers(actModel); + +%Check that the actual model is the same as the expected model +verifyEqual(testCase,actModel,expModel) +end diff --git a/testing/unit_tests/test_data/ecoli_textbook.mat b/testing/unit_tests/test_data/ecoli_textbook.mat new file mode 100644 index 00000000..546abbae Binary files /dev/null and b/testing/unit_tests/test_data/ecoli_textbook.mat differ