Home > io > exportToTabDelimited.m

exportToTabDelimited

PURPOSE ^

exportToTabDelimited

SYNOPSIS ^

function exportToTabDelimited(model,path,sortIds)

DESCRIPTION ^

 exportToTabDelimited
   Exports a model structure to a set of tab-delimited text files

   model    a model structure
   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 (optional, default false)

   NOTE: This functionality was previously a part of exportToExcelFormat.
         The naming of the resulting text files is to preserve backward
         compatibility

   NOTE: No checks are made regarding the correctness of the model. Use
         checkModelStruct to identify problems in the model structure

 Usage: exportToTabDelimited(model,path,sortIds)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function exportToTabDelimited(model,path,sortIds)
0002 % exportToTabDelimited
0003 %   Exports a model structure to a set of tab-delimited text files
0004 %
0005 %   model    a model structure
0006 %   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 %   sortIds logical whether metabolites, reactions and genes should be
0010 %           sorted alphabetically by their identifiers (optional, 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 if sortIds==true
0028     model=sortIdentifiers(model);
0029 end
0030 
0031 %If the folder doesn't exist then create it
0032 if ~isfolder(path)
0033     mkdir(path);
0034 end
0035 
0036 %Remove the files if they already exist
0037 if isfile(fullfile(path,'excelRxns.txt'))
0038     delete(fullfile(path,'excelRxns.txt'));
0039 end
0040 if isfile(fullfile(path,'excelMets.txt'))
0041     delete(fullfile(path,'excelMets.txt'));
0042 end
0043 if isfile(fullfile(path,'excelGenes.txt'))
0044     delete(fullfile(path,'excelGenes.txt'));
0045 end
0046 if isfile(fullfile(path,'excelModel.txt'))
0047     delete(fullfile(path,'excelModel.txt'));
0048 end
0049 if isfile(fullfile(path,'excelComps.txt'))
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     if isfield(model,'subSystems')
0108         if ~isempty(model.subSystems{i})
0109             if ~iscell(model.subSystems{i})
0110                 model.subSystems{i} = {model.subSystems{i}};
0111             end    
0112             fprintf(rxnFile,[strjoin(model.subSystems{i,1},';') '\t']);
0113         else
0114             fprintf(rxnFile,'\t');
0115         end
0116     end
0117     
0118     %Print replacement IDs
0119     fprintf(rxnFile,'\t');
0120     
0121     if isfield(model,'rxnNotes')
0122         fprintf(rxnFile,[model.rxnNotes{i} '\t']);
0123     else
0124         fprintf(rxnFile,'\t');
0125     end
0126     
0127     if isfield(model,'rxnReferences')
0128         fprintf(rxnFile,[model.rxnReferences{i} '\t']);
0129     else
0130         fprintf(rxnFile,'\t');
0131     end
0132     
0133     if isfield(model,'rxnConfidenceScores')
0134         fprintf(rxnFile,[num2str(model.rxnConfidenceScores(i)) '\t' ]);
0135     else
0136         fprintf(rxnFile,'\t');
0137     end
0138     
0139     fprintf(rxnFile,'\n');
0140 end
0141 
0142 fclose(rxnFile);
0143 
0144 %Open for printing the metabolites sheet
0145 metFile=fopen(fullfile(path,'excelMets.txt'),'wt');
0146 
0147 %Print header
0148 fprintf(metFile,'#\tID\tNAME\tUNCONSTRAINED\tMIRIAM\tCOMPOSITION\tInChI\tCOMPARTMENT\tREPLACEMENT ID\tMETS FIELD\tCHARGE\n');
0149 
0150 %Loop through the metabolites
0151 for i=1:numel(model.mets)
0152     fprintf(metFile,['\t' model.metNames{i} '[' model.comps{model.metComps(i)} ']\t' model.metNames{i} '\t']);
0153     
0154     if isfield(model,'unconstrained')
0155         if model.unconstrained(i)~=0
0156             fprintf(metFile,'TRUE\t');
0157         else
0158             fprintf(metFile,'\t');
0159         end
0160     else
0161         fprintf(metFile,'\t');
0162     end
0163     
0164     if isfield(model,'metMiriams')
0165         if ~isempty(model.metMiriams{i})
0166             toPrint=[];
0167             for j=1:numel(model.metMiriams{i}.name)
0168                 toPrint=[toPrint strtrim(model.metMiriams{i}.name{j}) '/' strtrim(model.metMiriams{i}.value{j}) ';'];
0169             end
0170             fprintf(rxnFile,[toPrint(1:end-1) '\t']);
0171         else
0172             fprintf(metFile,'\t');
0173         end
0174     else
0175         fprintf(metFile,'\t');
0176     end
0177     
0178     if isfield(model,'metFormulas')
0179         fprintf(metFile,[model.metFormulas{i} '\t']);
0180     else
0181         fprintf(metFile,'\t');
0182     end
0183     
0184     if isfield(model,'inchis')
0185         fprintf(metFile,[model.inchis{i} '\t']);
0186     else
0187         fprintf(metFile,'\t');
0188     end
0189     
0190     fprintf(metFile,[model.comps{model.metComps(i)} '\t']);
0191     
0192     %There can be no replacement IDs in the structure, but it has to be
0193     %something to give working met IDs.
0194     fprintf(metFile,['m' int2str(i) '\t']);
0195     
0196     %Print the model.mets field. The reason for not putting this as
0197     %replacement ID is that it's not guaranteed to be a valid SBML id.
0198     fprintf(metFile,[model.mets{i} '\t']);
0199     
0200     if isfield(model,'metCharges')
0201         fprintf(metFile,[num2str(model.metCharges(i)) '\t']);
0202     else
0203         fprintf(metFile,'\t');
0204     end
0205     
0206     fprintf(metFile,'\n');
0207 end
0208 
0209 fclose(metFile);
0210 
0211 if isfield(model,'genes')
0212     %Open for printing the genes sheet
0213     geneFile=fopen(fullfile(path,'excelGenes.txt'),'wt');
0214     
0215     %Print header
0216     fprintf(geneFile,'#\tNAME\tMIRIAM\tSHORT NAME\tCOMPARTMENT\n');
0217     
0218     %Loop through the genes
0219     for i=1:numel(model.genes)
0220         fprintf(geneFile,['\t' model.genes{i} '\t']);
0221         
0222         if isfield(model,'geneMiriams')
0223             if ~isempty(model.geneMiriams{i})
0224                 toPrint=[];
0225                 for j=1:numel(model.geneMiriams{i}.name)
0226                     toPrint=[toPrint strtrim(model.geneMiriams{i}.name{j}) '/' strtrim(model.geneMiriams{i}.value{j}) ';'];
0227                 end
0228                 fprintf(geneFile,[toPrint(1:end-1) '\t']);
0229             else
0230                 fprintf(geneFile,'\t');
0231             end
0232         else
0233             fprintf(geneFile,'\t');
0234         end
0235         
0236         if isfield(model,'geneShortNames')
0237             fprintf(geneFile,[model.geneShortNames{i} '\t']);
0238         else
0239             fprintf(geneFile,'\t');
0240         end
0241         
0242         if isfield(model,'geneComps')
0243             fprintf(geneFile,[model.comps{model.geneComps(i)} '\t']);
0244         else
0245             fprintf(geneFile,'\t');
0246         end
0247         
0248         fprintf(geneFile,'\n');
0249     end
0250     fclose(geneFile);
0251 end
0252 
0253 if isfield(model,'id')
0254     %Open for printing the model sheet
0255     modelFile=fopen(fullfile(path,'excelModel.txt'),'wt');
0256     
0257     %Print header
0258     fprintf(geneFile,'#\tID\tNAME\tDEFAULT LOWER\tDEFAULT UPPER\tCONTACT GIVEN NAME\tCONTACT FAMILY NAME\tCONTACT EMAIL\tORGANIZATION\tTAXONOMY\tNOTES\n');
0259     
0260     %Print model ID and name. It is assumed that the default lower/upper
0261     %bound correspond to min/max of the bounds
0262     toPrint=['\t' model.id '\t' model.name '\t'];
0263     if isfield(model,'annotation')
0264         if isfield(model.annotation,'defaultLB')
0265             toPrint=[toPrint num2str(model.annotation.defaultLB) '\t'];
0266         else
0267             toPrint=[toPrint num2str(min(model.lb)) '\t'];
0268         end
0269         if isfield(model.annotation,'defaultUB')
0270             toPrint=[toPrint num2str(model.annotation.defaultUB) '\t'];
0271         else
0272             toPrint=[toPrint num2str(max(model.ub)) '\t'];
0273         end
0274         if isfield(model.annotation,'givenName')
0275             toPrint=[toPrint model.annotation.givenName '\t'];
0276         else
0277             toPrint=[toPrint '\t'];
0278         end
0279         if isfield(model.annotation,'familyName')
0280             toPrint=[toPrint model.annotation.familyName '\t'];
0281         else
0282             toPrint=[toPrint '\t'];
0283         end
0284         if isfield(model.annotation,'email')
0285             toPrint=[toPrint model.annotation.email '\t'];
0286         else
0287             toPrint=[toPrint '\t'];
0288         end
0289         if isfield(model.annotation,'organization')
0290             toPrint=[toPrint model.annotation.organization '\t'];
0291         else
0292             toPrint=[toPrint '\t'];
0293         end
0294         if isfield(model.annotation,'taxonomy')
0295             toPrint=[toPrint model.annotation.taxonomy '\t'];
0296         else
0297             toPrint=[toPrint '\t'];
0298         end
0299         if isfield(model.annotation,'note')
0300             toPrint=[toPrint model.annotation.note '\t'];
0301         else
0302             toPrint=[toPrint '\t'];
0303         end
0304     else
0305         toPrint=[toPrint num2str(min(model.lb)) '\t' num2str(max(model.ub)) '\t\t\t\t\t\t\n'];
0306     end
0307     fprintf(modelFile,toPrint);
0308     fclose(modelFile);
0309 end
0310 
0311 if isfield(model,'comps')
0312     %Open for printing the model sheet
0313     compsFile=fopen(fullfile(path,'excelComps.txt'),'wt');
0314     
0315     %Print header
0316     fprintf(compsFile,'#\tABBREVIATION\tNAME\tINSIDE\tMIRIAM\n');
0317     
0318     for i=1:numel(model.comps)
0319         toPrint=['\t' model.comps{i} '\t' model.compNames{i} '\t'];
0320         if isfield(model,'compOutside')
0321             toPrint=[toPrint model.compOutside{i} '\t'];
0322         else
0323             toPrint=[toPrint '\t'];
0324         end
0325         if isfield(model,'compMiriams')
0326             if ~isempty(model.compMiriams{i})
0327                 for j=1:numel(model.compMiriams{i}.name)
0328                     toPrint=[toPrint strtrim(model.compMiriams{i}.name{j}) '/' strtrim(model.compMiriams{i}.value{j}) ';'];
0329                 end
0330                 toPrint(end)=[];
0331                 toPrint=[toPrint '\t'];
0332             else
0333                 toPrint=[toPrint '\t'];
0334             end
0335         else
0336             toPrint=[toPrint '\t'];
0337         end
0338         toPrint=[toPrint '\n'];
0339         fprintf(compsFile,toPrint);
0340     end
0341     fclose(compsFile);
0342 end
0343 end

Generated by m2html © 2005